Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365297

Summary: NullPointerException in JSPRenameChange
Product: [WebTools] WTP Source Editing Reporter: Mauro Molinari <mauromol>
Component: jst.jspAssignee: Nick Sandonato <nsand.dev>
Status: RESOLVED FIXED QA Contact: Nick Sandonato <nsand.dev>
Severity: normal    
Priority: P3 CC: thatnitind
Version: 3.3.1   
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mauro Molinari CLA 2011-12-01 06:13:03 EST
Build Identifier: 20110916-0149

After trying to do a Java refactoring (renaming a class used in a scriptlet) I got a NullPointer Exception in JSPRenameChange:

Participant 'org.eclipse.jst.jsp.ui.java.refactoring.JSPTypeRenameParticipant' removed due to the following exception

java.lang.NullPointerException
	at org.eclipse.jst.jsp.ui.internal.java.refactoring.JSPRenameChange.findOpenEditor(JSPRenameChange.java:233)
	at org.eclipse.jst.jsp.ui.internal.java.refactoring.JSPRenameChange.saveJSPFile(JSPRenameChange.java:183)
	at org.eclipse.jst.jsp.ui.internal.java.refactoring.JSPRenameChange.perform(JSPRenameChange.java:132)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation$1.run(PerformChangeOperation.java:258)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.executeChange(PerformChangeOperation.java:306)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:223)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4874)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:106)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
	at org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:759)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:756)
	at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2642)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:193)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:151)
	at org.eclipse.jdt.ui.refactoring.RenameSupport.perform(RenameSupport.java:198)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode.doRename(RenameLinkedMode.java:362)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode$EditorSynchronizer.left(RenameLinkedMode.java:119)
	at org.eclipse.jface.text.link.LinkedModeModel.exit(LinkedModeModel.java:341)
	at org.eclipse.jface.text.link.LinkedModeUI$4.run(LinkedModeUI.java:1194)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

Trying to repeat the same operation did not cause the exception anymore, but the JSP was not refactored and I had to adapt it by hand.

Reproducible: Sometimes

Steps to Reproduce:
Unfortunately I couldn't reproduce on a small test case. I hope the exception stack trace reveals something suspect by its own. By the way, the situation was one similar to the test project described in bug #365294, that is:
- Java class istantiated in a scriptlet of a JSP
- both the Java editor and the JSP editor open respectively on the Java class and on the JSP
- no compilation error in any of the two involved resources (class and JSP)
Comment 1 Nick Sandonato CLA 2011-12-06 14:57:12 EST
Thanks, Mauro. This NPE is likely caused by an editor that has not been instantiated yet (like the unfocused editors after launching a workbench). Refactoring then appeared to work out fine after that for the type renaming in the cases I ran. I've released the change.
Comment 2 Mauro Molinari CLA 2011-12-06 15:12:37 EST
Thanks to you Nick! This is very good news, because my refactorings were failing too often :-(

By the way (it's not about this bug), could those editor be the ones I sometimes see as completely blank when switching to them after startup? There's a bug about this: bug #240636. Do you have any idea or suggestion to reproduce that problem? Could there be a common cause?
Comment 3 Nick Sandonato CLA 2011-12-06 15:47:37 EST
(In reply to comment #2)
> Thanks to you Nick! This is very good news, because my refactorings were
> failing too often :-(
> 
> By the way (it's not about this bug), could those editor be the ones I
> sometimes see as completely blank when switching to them after startup? There's
> a bug about this: bug #240636. Do you have any idea or suggestion to reproduce
> that problem? Could there be a common cause?

You're welcome. You've been a great help in tracking down all of these refactoring bugs. I appreciate you helping us out.

There may be some relation. This NPE came from using platform API which explicitly states that it will return null for editors that haven't been instantiated yet. So I don't think that's a particular problem. It sounds like that should be expected. Maybe the same oversight we made is being done in bug 240636.