Community
Participate
Working Groups
Selecting some code within a method body and choosing "extract method" produces the following error: java.lang.NullPointerException at org.eclipse.jdt.core.dom.ASTConverter.checkForParenthesis(ASTConverter.java:2607) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:674) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1657) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1572) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:646) at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:228) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:168) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:73) at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:234) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring.checkActivation(ExtractMethodRefactoring.java:165) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:74) at org.eclipse.jdt.internal.ui.refactoring.actions.TextSelectionBasedRefactoringAction.run(TextSelectionBasedRefactoringAction.java:29) at org.eclipse.jdt.internal.ui.refactoring.actions.TextSelectionAction.run(TextSelectionAction.java:80) at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:202) at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:162) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent(ActionContributionItem.java:361) at org.eclipse.jface.action.ActionContributionItem.access$0(ActionContributionItem.java:352) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java:47) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:75) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:637) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1412) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1208) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:836) at org.eclipse.ui.internal.Workbench.run(Workbench.java:819) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:777) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:319) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:190) at org.eclipse.core.launcher.Main.run(Main.java:549) at org.eclipse.core.launcher.Main.main(Main.java:390)
It would be nice to know which build you are using and the piece of code you selected.
Build 20020416, JDK 1.4 While providing a test case i figured the bug only occurs if in the class contains an assert statement (JDK 1.4). This can be anywhere, not nesseccarily in the method to refactor. Testcase: Try extract method on a line of method bugTest() (will not work), then comment out the assert statement in containsAssert() and try again (will work): public class BugTest { public void bugTest() { System.out.println("bla"); System.out.println("blubb"); } private void containsAssert() { assert true; } }
Ok, thanks for the test case. I am working on it.
A quick question to be sure. Is your compiler set to accept assert statements?
Yes. Settings: Preferences -> Java -> Compiler -> Compiler compliance level: 1.4 Use default compliance settings. Everything compiles and works as expected (even "Organize Imports" which used to hickup on assert some builds ago)
I successfully reproduced the problem. It should be fixed today.
Fixed and released in HEAD.
Fixed.