Bug 29151

Summary: NPE in Surround with try/catch block [refactoring]
Product: [Eclipse Project] JDT Reporter: Andre Weinand <andre_weinand>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P2 CC: Darin_Swanson, dirk_baeumer, martinae, Michael.Valenta
Version: 2.1   
Target Milestone: 2.1 M5   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Andre Weinand CLA 2003-01-08 11:50:31 EST
I20030107

Had this code in editor:

		for (int i= 0; i < versions.length; i++) {
			String version= versions[i];
			if (findVMInstall(version) == null) {
				String path= "/System/Library/Frameworks/JavaVM.framework/Versions/"+version+"/Home";
				File home = new File(path); 
				if (home.exists()) {
					createVMInstall(version);
					if (javaHome != null && javaHome.equals(path)) {
						if (JavaRuntime.getDefaultVMInstall() == null) {
							IVMInstall vm= findVMInstall(version);
							if (vm != null) {
								JavaRuntime.setDefaultVMInstall(vm, null);
							}
						}
					}
				}
			}
		}
Comment 1 Andre Weinand CLA 2003-01-08 11:54:45 EST
[Oops, Safari seems to have problems with text pasted into this field...]

- selected line containing "JavaRuntime..."
- selected "surround with try/catch block" from context menu
- got this NPE:

!ENTRY org.eclipse.ui 4 0 Jan 08, 2003 17:57:22.179
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.corext.refactoring.changes.TextFileChange.perform(TextFileChange.java:203)
	at org.eclipse.jdt.internal.ui.refactoring.PerformChangeOperation$1.run(PerformChangeOperation.java:173)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:34)
	at org.eclipse.jdt.internal.core.JavaModelOperation.execute(JavaModelOperation.java:326)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:626)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1564)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:2571)
	at org.eclipse.jdt.internal.ui.refactoring.PerformChangeOperation.executeChange(PerformChangeOperation.java:183)
	at org.eclipse.jdt.internal.ui.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:151)
	at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.internalRun(BusyIndicatorRunnableContext.java:107)
	at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.run(BusyIndicatorRunnableContext.java:74)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:65)
	at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext.run(BusyIndicatorRunnableContext.java:120)
	at org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction.run(SurroundWithTryCatchAction.java:110)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:193)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:169)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:769)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:411)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent(ActionContributionItem.java:365)
	at org.eclipse.jface.action.ActionContributionItem.access$0(ActionContributionItem.java:356)
	at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java:48)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:77)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:623)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1252)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1009)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1467)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:1450)
	at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:845)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:462)
	at java.lang.reflect.Method.invoke(Native Method)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:247)
	at org.eclipse.core.launcher.Main.run(Main.java:703)
	at org.eclipse.core.launcher.Main.main(Main.java:539)
	at java.lang.reflect.Method.invoke(Native Method)
	at apple.launcher.LaunchRunner.run(LaunchRunner.java:88)
	at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50)
	at apple.launcher.JavaApplicationLauncher.launch(JavaApplicationLauncher.java:52)
java.lang.NullPointerException
Comment 2 Dirk Baeumer CLA 2003-01-20 08:36:57 EST
*** Bug 29547 has been marked as a duplicate of this bug. ***
Comment 3 Dirk Baeumer CLA 2003-01-20 08:37:20 EST
*** Bug 29549 has been marked as a duplicate of this bug. ***
Comment 4 Dirk Baeumer CLA 2003-01-20 08:42:33 EST
This is caused by code in the Java Core which magically converts an instance of 
a NullProgressMonitor into null. Your refactoring code doesn't assume at every 
place that the progress monitor can be null, since we make sure at the 
beginning of an operation that the progress monitor != null.

The problematic code is JavaModelOperation.run(...) {
			fMonitor = monitor instanceof NullProgressMonitor ? 
null/*workaround for http://bugs.eclipse.org/bugs/show_bug.cgi?id=25529*/ : 
monitor;

}

IMO core can't replace a valid progress monitor through null even if it is an 
instance of NullProgressMonitor since this can cause NPE.

Moving to JDT Core.
Comment 5 Olivier Thomann CLA 2003-01-22 12:27:58 EST
I removed this check that replace NullProgressMonitor with null. All JDT/Core
tests passed.
Fixed and released in 2.1 stream.
Comment 6 Dirk Baeumer CLA 2003-01-23 03:52:25 EST
*** Bug 30023 has been marked as a duplicate of this bug. ***
Comment 7 David Audel CLA 2003-02-11 09:10:58 EST
Verified.