Project: JDT
Bug 41148 Extract Method doesn't check for null type [refactoring]
Reported: 2003-08-05 11:29:44 | Status: resolved fixed

public class Q { void f() { String str= (null); str= (true ? null : null); } } - Select "(null)" - Choose menu Refactor > Extract Method... -> Exception below is thrown. The problem here is that ExtractMethodAnalyzer::checkExpression doesn't look inside parenthesized expressions and excludes only plain NullLiterals. The patch I will attach solves the problem for all expressions of null type. It makes the special handling of NullLiterals in ExtractMethodAnalyzer::checkExpression superfluous. java.lang.IllegalArgumentException at org.eclipse.jdt.core.dom.SimpleName.setIdentifier(SimpleName.java:125) at org.eclipse.jdt.core.dom.AST.newSimpleName(AST.java:1129) at org.eclipse.jdt.core.dom.AST.newName(AST.java:1177) at org.eclipse.jdt.internal.corext.dom.ASTNodeFactory.newType(ASTNodeFactory.java:92) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodAnalyzer.initReturnType(ExtractMethodAnalyzer.java:213) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodAnalyzer.checkActivation(ExtractMethodAnalyzer.java:181) at org.eclipse.jdt.internal.corext.refactoring.code.ExtractMethodRefactoring.checkActivation(ExtractMethodRefactoring.java:177) at org.eclipse.jdt.internal.ui.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:63) at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.internalRun(BusyIndicatorRunnableContext.java:113) at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.run(BusyIndicatorRunnableContext.java:80) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:84) at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext.run(BusyIndicatorRunnableContext.java:126) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.checkActivation(RefactoringStarter.java:66) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:46) at org.eclipse.jdt.ui.actions.ExtractMethodAction.run(ExtractMethodAction.java:70) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:196) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:172) at org.eclipse.jface.action.Action.runWithEvent(Action.java:842) at org.eclipse.ui.actions.RetargetAction.runWithEvent(RetargetAction.java:187) at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:212) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:542) at org.eclipse.jface.action.ActionContributionItem.access$4(ActionContributionItem.java:496) at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:468) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2188) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1878) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1680) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1663) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) 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:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)

Files changed in fix:
org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodAnalyzer.java