Bug 19851 - IllegalArgumentException in refactor-extract method
Summary: IllegalArgumentException in refactor-extract method
Status: RESOLVED DUPLICATE of bug 18708
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.0 F3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-10 17:28 EDT by Peter Burka CLA
Modified: 2002-06-11 11:19 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Burka CLA 2002-06-10 17:28:45 EDT
Build F2

I selected three lines of code in a .java file and chose 'Refactor'->'Extract 
Method'. The following IllegalArgumentException was recorded in my .log file:

java.lang.IllegalArgumentException

Stack trace:
   java/lang/Throwable.<init>()V
   org/eclipse/jdt/core/dom/ASTNode.setSourceRange(II)V
   org/eclipse/jdt/core/dom/ASTConverter.checkAndAddMultipleFieldDeclaration
([Lorg/eclipse/jdt/internal/compiler/ast/FieldDeclaration;ILjava/util/List;)V
   org/eclipse/jdt/core/dom/ASTConverter.buildBodyDeclarations
(Lorg/eclipse/jdt/internal/compiler/ast/TypeDeclaration;Lorg/eclipse/jdt/core/d
om/TypeDeclaration;)V
   org/eclipse/jdt/core/dom/ASTConverter.convert
(Lorg/eclipse/jdt/internal/compiler/ast/TypeDeclaration;)
Lorg/eclipse/jdt/core/dom/TypeDeclaration;
   org/eclipse/jdt/core/dom/ASTConverter.convert
(Lorg/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration;[C)
Lorg/eclipse/jdt/core/dom/CompilationUnit;
   org/eclipse/jdt/core/dom/AST.parseCompilationUnit
(Lorg/eclipse/jdt/core/ICompilationUnit;Z)
Lorg/eclipse/jdt/core/dom/CompilationUnit;
   
org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodRefactoring.check
Activation(Lorg/eclipse/core/runtime/IProgressMonitor;)
Lorg/eclipse/jdt/internal/corext/refactoring/base/RefactoringStatus;
   org/eclipse/jdt/internal/ui/refactoring/actions/RefactoringStarter.activate
(Lorg/eclipse/jdt/internal/corext/refactoring/base/Refactoring;Lorg/eclipse/jdt
/internal/ui/refactoring/RefactoringWizard;Ljava/lang/String;Z)
Ljava/lang/Object;
   org/eclipse/jdt/ui/actions/ExtractMethodAction.run
(Lorg/eclipse/jface/text/ITextSelection;)V
   org/eclipse/jdt/ui/actions/SelectionDispatchAction.dispatchRun
(Lorg/eclipse/jface/viewers/ISelection;)V
   org/eclipse/jdt/ui/actions/SelectionDispatchAction.run()V
   org/eclipse/jface/action/Action.runWithEvent
(Lorg/eclipse/swt/widgets/Event;)V
   org/eclipse/ui/actions/RetargetAction.runWithEvent
(Lorg/eclipse/swt/widgets/Event;)V
   org/eclipse/ui/internal/WWinPluginAction.runWithEvent
(Lorg/eclipse/swt/widgets/Event;)V
   org/eclipse/jface/action/ActionContributionItem.handleWidgetSelection
(Lorg/eclipse/swt/widgets/Event;)V
   org/eclipse/jface/action/ActionContributionItem.handleWidgetEvent
(Lorg/eclipse/swt/widgets/Event;)V
   org/eclipse/jface/action/ActionContributionItem.access$0
(Lorg/eclipse/jface/action/ActionContributionItem;Lorg/eclipse/swt/widgets/Even
t;)V
   org/eclipse/jface/action/ActionContributionItem$ActionListener.handleEvent
(Lorg/eclipse/swt/widgets/Event;)V
   org/eclipse/swt/widgets/EventTable.sendEvent
(Lorg/eclipse/swt/widgets/Event;)V
   org/eclipse/swt/widgets/Widget.sendEvent(Lorg/eclipse/swt/widgets/Event;)V
   org/eclipse/swt/widgets/Display.runDeferredEvents()Z
   org/eclipse/swt/widgets/Display.readAndDispatch()Z
   org/eclipse/ui/internal/Workbench.runEventLoop()V
   org/eclipse/ui/internal/Workbench.run(Ljava/lang/Object;)Ljava/lang/Object;
   org/eclipse/core/internal/boot/InternalBootLoader.run
(Ljava/lang/String;Ljava/net/URL;Ljava/lang/String;
[Ljava/lang/String;Ljava/lang/Runnable;)Ljava/lang/Object;
   org/eclipse/core/boot/BootLoader.run
(Ljava/lang/String;Ljava/net/URL;Ljava/lang/String;
[Ljava/lang/String;Ljava/lang/Runnable;)Ljava/lang/Object;
   java/lang/reflect/AccessibleObject.invokeL(Ljava/lang/Object;
[Ljava/lang/Object;)Ljava/lang/Object;
   java/lang/reflect/Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)
Ljava/lang/Object;
   org/eclipse/core/launcher/Main.basicRun([Ljava/lang/String;)
Ljava/lang/Object;
   org/eclipse/core/launcher/Main.run([Ljava/lang/String;)Ljava/lang/Object;
   org/eclipse/core/launcher/Main.main([Ljava/lang/String;)V

I was able to repeat the problem with a stripped down version of the class.

Enter the following class into a Java editor:

public class Foo {

	protected void primExecute() {
		this.toString();
	}

	if (image != null) {
		Object loc = null;
	}
}

Select the 'this.toString()' line.
Choose 'Refactor'->'Extract Method'
Comment 1 Adam Kiezun CLA 2002-06-11 04:44:31 EDT
i think the problem is on our (refactoring) side
this class is so messed up that cu.isStructureKnown() returns false
we should guard our code against it
Comment 2 Adam Kiezun CLA 2002-06-11 05:04:46 EDT
more actions fail:
OrganizeImport
SurroundWithTryCatch
Rename (when you select sth in the file)
SelfEncapsulateField (add a field, select and invoke the action)

i suggest moving to the ui land and putting guards in the  ui actions
Comment 3 Dirk Baeumer CLA 2002-06-11 07:06:02 EDT
I don't agree with this. As we can see from the walkback there is an old AST 
which somehow can't be converted into a new AST. Even if the CU is totally 
broken creating an AST for it should not result in an IllegalArgumentException. 
What I would expect to get is an AST containing only a CompilationUnitNode.
Comment 4 Philipe Mulet CLA 2002-06-11 07:07:16 EDT
Pls investigate - internal calls should never result in invalid argument 
exceptions.
Comment 5 Olivier Thomann CLA 2002-06-11 11:05:28 EDT
I cannot reproduce in latest. This seems to be a duplicate of bug 18708. I got 
the following cu after applying refact -> extract method on the selected line:

public class Foo {

        protected void primExecute() {
                test();
        }

	private String test() {
		return this.toString();
	}

        if (image != null) {
                Object loc = null;
        }
}
Comment 6 Olivier Thomann CLA 2002-06-11 11:18:23 EDT
I could reproduce in F2, but not in latest. So this is a duplicate of bug 18708.

*** This bug has been marked as a duplicate of 18708 ***