Project: JDT
Bug 46933 refactoring: NPE when using "Generalize Type" on field in local type
Reported: 2003-11-19 05:42:52 | Status: resolved fixed

I20031119 (M5 test pass) 1. have this code: public class Test { public void foobar() { class Listener3 { private Test fTest; private Listener3() { fTest= new Test(); } public int bar() { return foo(); } public int foo() { return 1; } private String getProperty() { return null; } } this.addListener(new Listener3() { public int bar() { return 1; } }); } public void addListener(Object o) { } } 2. Select the type name ('Test') of field fTest in the local type 3. Choose Refactor->Generalize Type -> The dialog comes up, but then an exception is thrown, stack trace of the inner exception (inside a runnable): java.lang.NullPointerException at java.lang.Throwable.<init>(Throwable.java) at java.lang.Throwable.<init>(Throwable.java) at java.lang.NullPointerException.<init>(NullPointerException.java:60) at org.eclipse.jdt.internal.ui.refactoring.ChangeTypeWizard$ChangeTypeInputPage$ValidTypesTask.run(ChangeTypeWizard.java:173) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.jface.window.Window.runEventLoop(Window.java:583) at org.eclipse.jface.window.Window.open(Window.java:563) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:56) at org.eclipse.jdt.ui.actions.ChangeTypeAction.run(ChangeTypeAction.java:75) 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.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:542) at org.eclipse.jface.action.ActionContributionItem.access$4(ActionContributionItem.java:494) at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1405) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1381) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:237) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:139) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:47) 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:79) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41) at java.lang.reflect.Method.invoke(Method.java:386) at org.eclipse.core.launcher.Main.basicRun(Main.java:299) at org.eclipse.core.launcher.Main.run(Main.java:767) at org.eclipse.core.launcher.Main.main(Main.java:601)

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ChangeTypeRefactoring/negative/A_testFieldOfLocalType_in.java org.eclipse.jdt.ui.tests.refactoring/resources/ChangeTypeRefactoring/negative/A_testFieldOfLocalType_out.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeTypeRefactoringTests.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ChangeTypeRefactoring.java org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/ChangeTypeWizard.java