Bug 127346 [quick assist] NPE during clean up wizard "for loop conversion"
The following NPE occurs with 3.2m4 and also with latest integration build 20060210 with "for loop conversion": eclipse.buildId=I20060210-1214 java.version=1.5.0_06 java.vendor=Sun Microsystems Inc. BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=de_DE Command-line arguments: -data C:\Program Files\Eclipse 3.2 M4\workspace -os win32 -ws win32 -arch x86 Error 2006-02-10 23:26:50.105 Internal Error java.lang.reflect.InvocationTargetException at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:341) at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:833) at org.eclipse.ltk.ui.refactoring.RefactoringWizard.createChange(RefactoringWizard.java:571) at org.eclipse.ltk.ui.refactoring.RefactoringWizard.computeUserInputSuccessorPage(RefactoringWizard.java:414) at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.computeSuccessorPage(UserInputWizardPage.java:75) at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.getNextPage(UserInputWizardPage.java:115) at org.eclipse.jdt.internal.ui.fix.CleanUpRefactoringWizard$SelectCleanUpPage.getNextPage(CleanUpRefactoringWizard.java:457) at org.eclipse.jface.wizard.WizardDialog.nextPressed(WizardDialog.java:737) at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:345) at org.eclipse.jface.dialogs.Dialog$3.widgetSelected(Dialog.java:645) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:925) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3287) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2907) at org.eclipse.jface.window.Window.runEventLoop(Window.java:811) at org.eclipse.jface.window.Window.open(Window.java:789) at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:132) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69) at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:145) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:40) at org.eclipse.jdt.internal.ui.actions.CleanUpAction.runOnMultiple(CleanUpAction.java:227) at org.eclipse.jdt.internal.ui.actions.CleanUpAction.run(CleanUpAction.java:96) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:267) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:243) at org.eclipse.jface.action.Action.runWithEvent(Action.java:492) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:530) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:480) at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:392) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:925) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3287) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2907) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1830) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1794) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:410) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:106) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:99) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:374) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:169) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.core.launcher.Main.invokeFramework(Main.java:338) at org.eclipse.core.launcher.Main.basicRun(Main.java:282) at org.eclipse.core.launcher.Main.run(Main.java:977) at org.eclipse.core.launcher.Main.main(Main.java:952) Caused by: java.lang.NullPointerException at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.doInferCollectionFromExpression(ConvertForLoopOperation.java:694) at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.doInferCollectionFromInitializers(ConvertForLoopOperation.java:676) at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.doInferCollection(ConvertForLoopOperation.java:626) at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.arrayCanBeInferred(ConvertForLoopOperation.java:403) at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.satisfiesPreconditions(ConvertForLoopOperation.java:187) at org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder.visit(ControlStatementsFix.java:104) at org.eclipse.jdt.core.dom.ForStatement.accept0(ForStatement.java:222) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2536) at org.eclipse.jdt.core.dom.Block.accept0(Block.java:135) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2513) at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:501) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2536) at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:483) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2536) at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:212) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.internal.corext.fix.ControlStatementsFix.createCleanUp(ControlStatementsFix.java:369) at org.eclipse.jdt.internal.ui.fix.ControlStatementsCleanUp.createFix(ControlStatementsCleanUp.java:79) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring$SolutionGenerator.calculateSolution(CleanUpRefactoring.java:175) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring$SolutionGenerator.acceptAST(CleanUpRefactoring.java:153) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:708) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:461) at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:693) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring.parse(CleanUpRefactoring.java:454) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring.cleanUpProject(CleanUpRefactoring.java:384) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring.checkFinalConditions(CleanUpRefactoring.java:336) at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:83) at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:117) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1733) at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113) Root exception: java.lang.NullPointerException at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.doInferCollectionFromExpression(ConvertForLoopOperation.java:694) at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.doInferCollectionFromInitializers(ConvertForLoopOperation.java:676) at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.doInferCollection(ConvertForLoopOperation.java:626) at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.arrayCanBeInferred(ConvertForLoopOperation.java:403) at org.eclipse.jdt.internal.corext.fix.ConvertForLoopOperation.satisfiesPreconditions(ConvertForLoopOperation.java:187) at org.eclipse.jdt.internal.corext.fix.ControlStatementsFix$ControlStatementFinder.visit(ControlStatementsFix.java:104) at org.eclipse.jdt.core.dom.ForStatement.accept0(ForStatement.java:222) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2536) at org.eclipse.jdt.core.dom.Block.accept0(Block.java:135) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2513) at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:501) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2536) at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:483) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2536) at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:212) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466) at org.eclipse.jdt.internal.corext.fix.ControlStatementsFix.createCleanUp(ControlStatementsFix.java:369) at org.eclipse.jdt.internal.ui.fix.ControlStatementsCleanUp.createFix(ControlStatementsCleanUp.java:79) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring$SolutionGenerator.calculateSolution(CleanUpRefactoring.java:175) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring$SolutionGenerator.acceptAST(CleanUpRefactoring.java:153) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:708) at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:461) at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:693) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring.parse(CleanUpRefactoring.java:454) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring.cleanUpProject(CleanUpRefactoring.java:384) at org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring.checkFinalConditions(CleanUpRefactoring.java:336) at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:83) at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:117) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1733) at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertForLoopQuickFixTest.java
buf.append("package test1;\n");
		buf.append("public class A {\n");
		buf.append("    public void foo() {\n");
		buf.append("		String[] array = {\"1\",\"2\"};\n");
		buf.append("		for (String element : array) {\n");
		buf.append("			if (element.equals(\"2\"))\n");
		buf.append("				System.out.println(element);\n");
		buf.append("			else if ((element + 2) == \"4\"){\n");
		buf.append("				int k = Integer.parseInt(element) - 2;\n");
		buf.append("			}\n");
		buf.append("		}\n");
		buf.append("    }\n");
		buf.append("}\n");
		String expected= buf.toString();
		assertEqualString(preview1, expected);
	}
	public void testNiceReduction() throws Exception {
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
		StringBuffer buf= new StringBuffer();
		buf.append("package test1;\n");
		buf.append("class Weirdy{}\n");
		buf.append("private Weirdy[] weirdies;\n");
		buf.append("public class A {\n");
		buf.append("    public void foo(){\n");
		buf.append("		for (int i = 0, length = weirdies.length; i < length; i++){\n");
		buf.append("			System.out.println();\n");
		buf.append("		    Weirdy p = weirdies[i];\n");
		buf.append("		    if (p != null){\n");
		buf.append("				System.out.println(p);\n");
		buf.append("	    	}\n");