Bug 101863 - [refactoring] Move member type to new file: assertion failure
Summary: [refactoring] Move member type to new file: assertion failure
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Tobias Widmer CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
: 102483 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-27 09:23 EDT by Tom Hofmann CLA Friend
Modified: 2005-12-13 05:42 EST (History)
4 users (show)

See Also:


Attachments
PreferencesView.java (17.98 KB, text/x-java)
2005-06-27 09:24 EDT, Tom Hofmann CLA Friend
no flags Details
proposed fix (1.22 KB, patch)
2005-08-10 09:05 EDT, Tobias Widmer CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA Friend 2005-06-27 09:23:37 EDT
3.1-RC4

- have the CU I will attach
- try to Refactor>Move Nested Type to New File on nested type 'Domain<T>'

-> AFE:

Caused by: org.eclipse.jdt.internal.corext.Assert$AssertionFailedException: null
argument;
	at org.eclipse.jdt.internal.corext.Assert.isNotNull(Assert.java:108)
	at org.eclipse.jdt.internal.corext.Assert.isNotNull(Assert.java:86)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring.findTypeDeclaration(MoveInnerToTopRefactoring.java:406)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring.createNewSource(MoveInnerToTopRefactoring.java:1018)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring.createChangeManager(MoveInnerToTopRefactoring.java:839)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring.checkFinalConditions(MoveInnerToTopRefactoring.java:743)
	at
org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:84)
	at
org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:114)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1719)
	at
org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:86)
	at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Comment 1 Tom Hofmann CLA Friend 2005-06-27 09:24:38 EDT
Created attachment 24029 [details]
PreferencesView.java

Java file as described in comment 0.
Comment 2 Tobias Widmer CLA Friend 2005-06-27 11:08:15 EDT
Unfortunately, it's a regression: The AFE happens in situations where a top-
level class contains more than one direct member type and the refactoring is 
not applied to the first one. It has nothing to do with generics and/or enums. 

All other cases work fine.

Workaround is to move the class to be refactored to the first position within 
the top-level type.
Comment 3 Tobias Widmer CLA Friend 2005-06-27 11:13:38 EDT
Comment 2 is only partially correct: The following case works fine:

public class Foo{
	class Bar1{
	}
	class Bar2{
	}
	class Bar3{
	}
}

Since the fix does not seem very easy and there is no general pattern to 
produce the failure, I suggest to leave this for 3.1.
Comment 4 Tobias Widmer CLA Friend 2005-06-27 12:12:56 EDT
I was finally able to track down the problem: During rewriting of the inner 
class, a new AST is created, but the ASTParser is not currently set up (only a 
call to setSource)

The result is that the parser is trying to parse 5.0 code in 1.4 compliance 
mode. The enum keyword in the code example causes unrecoverable problems to 
the parser, which results in a compilation unit node where some the inner 
types after the enum appear as top-level types, causing the refactoring to 
fail.

This defect is not an actual regression, since it is not caused by changes in 
the refactoring code, but by the fact that the setup of the ASTParser 
described above is not sufficent anymore for 5.0 code, but is still for 1.4.

The fix is to call ASTParser#setProject(...) before creating the AST.
Comment 5 Martin Aeschlimann CLA Friend 2005-06-27 12:23:29 EDT
Will not fix for 3.1 for the following reasons:

- inner enums or inner classes inside enums are both special cases
- the refactoring fails, but does no harm

I suggest to add this to the list of 3.1.1 bugs
Comment 6 Tobias Widmer CLA Friend 2005-06-27 12:26:20 EDT
The refactoring works correctly wrt. this bug for all <= 1.4 code.
The only setup that is causing the AFE is a class which is moved out of a 5.0 
compliant compilation unit where enums are declared with a source offset less 
than the offset of the class to be refactored.
All other scenarios work fine.
Comment 7 Dirk Baeumer CLA Friend 2005-06-27 12:30:49 EDT
Given this I opt to postpone the bug to 3.1.1.
Comment 8 Tobias Widmer CLA Friend 2005-06-30 04:54:09 EDT
Fixed in HEAD > 20050630
Comment 9 Dirk Baeumer CLA Friend 2005-07-02 13:47:59 EDT
*** Bug 102483 has been marked as a duplicate of this bug. ***
Comment 10 Tobias Widmer CLA Friend 2005-08-10 08:54:49 EDT
Martin, can you please yote?
Comment 11 Tobias Widmer CLA Friend 2005-08-10 08:56:17 EDT
Dirk, can you please vote?
Comment 12 Dirk Baeumer CLA Friend 2005-08-10 09:03:57 EDT
Tobias, can you please provide a patch we can vote on ?
Comment 13 Tobias Widmer CLA Friend 2005-08-10 09:05:49 EDT
Created attachment 25965 [details]
proposed fix
Comment 14 Martin Aeschlimann CLA Friend 2005-08-10 10:22:06 EDT
patch looks good. 
Comment 15 Dirk Baeumer CLA Friend 2005-08-10 11:11:25 EDT
Patch looks good to me.
Comment 16 Tobias Widmer CLA Friend 2005-08-10 12:03:08 EDT
Fixed in 3.1.1 maintenance stream > 20050810
Comment 17 Tom Hofmann CLA Friend 2005-09-02 09:53:09 EDT
verifying...
Comment 18 Tom Hofmann CLA Friend 2005-09-02 10:05:42 EDT
verified the "Move to its own CU" refactoring works as expected in the described
scenarios.
Comment 19 Tobias Widmer CLA Friend 2005-12-13 05:42:56 EST
*** Bug 120432 has been marked as a duplicate of this bug. ***