Bug 38951 - NPE in editor while saving contents
Summary: NPE in editor while saving contents
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P1 major (vote)
Target Milestone: 3.0 M2   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 38969 39019 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-06-16 09:53 EDT by Philipe Mulet CLA
Modified: 2003-07-17 12:25 EDT (History)
5 users (show)

See Also:


Attachments
Zipped editor contents (53.23 KB, application/octet-stream)
2003-06-16 09:58 EDT, Philipe Mulet CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2003-06-16 09:53:20 EDT
Build 3.0[20030611]

When saving editor contents, error dialog 'save failed reason: null' popped up.
In log following entry got logged:

!ENTRY org.eclipse.ui 4 4 Jun 16, 2003 15:49:23.534
!MESSAGE Save Failed
Save Failed
Reason:
!ENTRY org.eclipse.ui 2 0 Jun 16, 2003 15:49:23.554
!MESSAGE Save Failed
!STACK 0
java.lang.NullPointerException
        at 
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.doSaveDoc
ument(CompilationUnitDocumentProvider.java:909)
        at org.eclipse.ui.texteditor.AbstractDocumentProvider.saveDocument
(AbstractDocumentProvider.java:459)
        at org.eclipse.ui.texteditor.AbstractTextEditor$11.execute
(AbstractTextEditor.java:3072)
        at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run
(WorkspaceModifyOperation.java:71)
        at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1595)
        at org.eclipse.ui.actions.WorkspaceModifyOperation.run
(WorkspaceModifyOperation.java:85)
        at org.eclipse.ui.texteditor.AbstractTextEditor.performSaveOperation
(AbstractTextEditor.java:3092)
        at 
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.performSaveOperatio
n(CompilationUnitEditor.java:754)
        at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSave
(CompilationUnitEditor.java:818)
        at org.eclipse.ui.internal.EditorManager$11.run(EditorManager.java:1090)
        at org.eclipse.ui.internal.EditorManager$8.run(EditorManager.java:960)
        at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:302)
        at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:252)
        at org.eclipse.jface.window.ApplicationWindow$1.run
(ApplicationWindow.java:431)
        at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
        at org.eclipse.jface.window.ApplicationWindow.run
(ApplicationWindow.java:428)
        at org.eclipse.ui.internal.WorkbenchWindow.run
(WorkbenchWindow.java:1332)
        at org.eclipse.ui.internal.EditorManager.runProgressMonitorOperation
(EditorManager.java:966)
        at org.eclipse.ui.internal.EditorManager.savePart
(EditorManager.java:1095)
        at org.eclipse.ui.internal.WorkbenchPage.savePart
(WorkbenchPage.java:2351)
        at org.eclipse.ui.internal.WorkbenchPage.saveEditor
(WorkbenchPage.java:2363)
        at org.eclipse.ui.internal.SaveAction.run(SaveAction.java:57)
        at org.eclipse.jface.action.Action.runWithEvent(Action.java:842)
        at org.eclipse.ui.internal.WWinKeyBindingService.pressed
(WWinKeyBindingService.java:214)
        at org.eclipse.ui.internal.WWinKeyBindingService$5.widgetSelected
(WWinKeyBindingService.java:332)
        at org.eclipse.ui.internal.AcceleratorMenu$2.handleEvent
(AcceleratorMenu.java:68)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2036)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1742)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1399)
        at org.eclipse.ui.internal.Workbench.run(Workbench.java:1382)
        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)
Save Failed
Comment 1 Philipe Mulet CLA 2003-06-16 09:55:37 EDT
Raising severity since dataloss is possible due to this bug (may loose unsaved 
changes)
Comment 2 Philipe Mulet CLA 2003-06-16 09:58:23 EDT
Created attachment 5200 [details]
Zipped editor contents

This source corresponds to the class:
org.eclipse.jdt.internal.compiler.parser.Parser
Comment 3 Philipe Mulet CLA 2003-06-16 10:01:21 EDT
Actually, reassigning to JDT/Core for further analysis. Suspecting some side-
effect related to new working copies management (was running patched JDT/Core).

Comment 4 Philipe Mulet CLA 2003-06-16 10:13:38 EDT
If closing editor (discarding unsaved changes), then cannot open editor again 
since it complains it has the wrong type of shared working copy.
Comment 5 Philipe Mulet CLA 2003-06-16 10:14:32 EDT
!ENTRY org.eclipse.jdt.ui 4 10002 Jun 16, 2003 16:10:21.933
!MESSAGE Shared working copy has wrong buffer
!STACK 0
java.lang.ClassCastException
        at 
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.createEle
mentInfo(CompilationUnitDocumentProvider.java:852)
        at org.eclipse.ui.texteditor.AbstractDocumentProvider.connect
(AbstractDocumentProvider.java:306)
        at org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput
(AbstractTextEditor.java:2422)
        at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput
(StatusTextEditor.java:162)
        at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.doSetInput
(JavaEditor.java:1585)
        at 
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSetInput
(CompilationUnitEditor.java:940)
        at org.eclipse.ui.texteditor.AbstractTextEditor$8.run
(AbstractTextEditor.java:1906)
        at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:302)
        at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:252)
        at org.eclipse.jface.window.ApplicationWindow$1.run
(ApplicationWindow.java:431)
        at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
        at org.eclipse.jface.window.ApplicationWindow.run
(ApplicationWindow.java:428)
        at org.eclipse.ui.internal.WorkbenchWindow.run
(WorkbenchWindow.java:1332)
        at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit
(AbstractTextEditor.java:1921)
        at org.eclipse.ui.texteditor.AbstractTextEditor.init
(AbstractTextEditor.java:1938)
        at org.eclipse.ui.internal.EditorManager.createSite
(EditorManager.java:604)
        at org.eclipse.ui.internal.EditorManager.openInternalEditor
(EditorManager.java:666)
        at org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor
(EditorManager.java:459)
        at org.eclipse.ui.internal.EditorManager.openEditorFromInput
(EditorManager.java:333)
        at org.eclipse.ui.internal.EditorManager.openEditor
(EditorManager.java:424)
        at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor
(WorkbenchPage.java:2051)
        at org.eclipse.ui.internal.WorkbenchPage.access$6
(WorkbenchPage.java:1999)
        at org.eclipse.ui.internal.WorkbenchPage$9.run(WorkbenchPage.java:1986)
        at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
        at org.eclipse.ui.internal.WorkbenchPage.openEditor
(WorkbenchPage.java:1981)
        at org.eclipse.ui.internal.WorkbenchPage.openEditor
(WorkbenchPage.java:1882)
        at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor
(EditorUtility.java:133)
        at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor
(EditorUtility.java:111)
        at org.eclipse.jdt.internal.ui.actions.OpenTypeAction.run
(OpenTypeAction.java:67)
        at org.eclipse.jdt.internal.ui.actions.OpenTypeAction.run
(OpenTypeAction.java:80)
        at org.eclipse.ui.internal.PluginAction.runWithEvent
(PluginAction.java:263)
        at org.eclipse.ui.internal.WWinPluginAction.runWithEvent
(WWinPluginAction.java:207)
        at org.eclipse.ui.internal.WWinKeyBindingService.pressed
(WWinKeyBindingService.java:214)
        at org.eclipse.ui.internal.WWinKeyBindingService$5.widgetSelected
(WWinKeyBindingService.java:332)
        at org.eclipse.ui.internal.AcceleratorMenu$2.handleEvent
(AcceleratorMenu.java:68)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2036)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1742)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1399)
        at org.eclipse.ui.internal.Workbench.run(Workbench.java:1382)
        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)
Comment 6 Philipe Mulet CLA 2003-06-16 10:16:49 EDT
Offending code is attempting to cast to 'DocumentAdapter'. Presumably, a bogus 
working copy got stuck in place of the shared one.

Suspecting original unit took place of shared one.
Comment 7 Philipe Mulet CLA 2003-06-16 11:03:08 EDT
Some tracing shown that it is related to buffer cache flushing. Underlying CU 
buffer got closed, and it seems to have interfered with wc buffer from thereon.

Hard to reproduce though (need to get close to model cache flushing mode).
Comment 8 Jerome Lanneluc CLA 2003-06-16 13:34:41 EDT
Workaround added to never flush working copies from the cache until they are 
destroyed (Compilation.hasUnsavedChanges() always returns true for working 
copies).
Comment 9 Philipe Mulet CLA 2003-06-16 14:53:31 EDT
Things to clean:
- remove negative useCount support
- ensure no way to get a handle onto working copy with unit info. Info creation 
must use working copy for these type of handles. For primary ones, may need to 
remember which kind to use (owner's implementation?)
Comment 10 Philipe Mulet CLA 2003-06-16 18:34:28 EDT
Problem reproduced by changing Openable cache size down to 10, and using self-
hosted JDT/Core. 

Issue is caused by the fact the edited working copy is getting closed when 
opened since cache is full (and for the duration of the editor opening, the 
buffer hasn't been changed yet). Thus editor creates working copy, which gets 
closed immediately. However, since the working copy got closed, it inserted a 
fake info (negative use count) to remember its working copy nature (as handle 
is true unit).

When some UI refresh is triggered, then the working copy is populated through 
one of its children (source method needs refresh, likely overriding indicator), 
and thus a new info is created from scratch (as fake info never made it to the 
cache, it only got added temporarily, but purged anyway).

If working copies are to tolerated being closed halfway through, then their 
regular opening (through createElementInfo()) should be able to create the 
proper info kind.

Never flushing them doesn't strike me as it is consistent with their buffer 
management (i.e. workaround looks good actually).
Comment 11 Dani Megert CLA 2003-06-17 03:44:52 EDT
*** Bug 38969 has been marked as a duplicate of this bug. ***
Comment 12 Dani Megert CLA 2003-06-17 04:47:40 EDT
I got the NPE again using the newest J Core stuff (downloaded the patch this
morning from the JDT Core page).
I had to close the editor but now I can no longer open the file: Shared Working
Copy has wrong buffer.
Comment 13 Dani Megert CLA 2003-06-17 04:48:15 EDT
This was in the .log:
!ENTRY org.eclipse.jdt.ui 4 10002 Jun 17, 2003 10:44:56.275
!MESSAGE Shared working copy has wrong buffer
!STACK 0
java.lang.ClassCastException
	at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.createElementInfo(CompilationUnitDocumentProvider.java:852)
	at
org.eclipse.ui.texteditor.AbstractDocumentProvider.connect(AbstractDocumentProvider.java:306)
	at
org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput(AbstractTextEditor.java:2422)
	at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput(StatusTextEditor.java:162)
	at
org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.doSetInput(JavaEditor.java:1585)
	at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSetInput(CompilationUnitEditor.java:940)
	at org.eclipse.ui.texteditor.AbstractTextEditor$8.run(AbstractTextEditor.java:1906)
	at
org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:302)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:252)
	at org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:431)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
	at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:428)
	at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:1332)
	at
org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:1921)
	at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:1938)
	at org.eclipse.ui.internal.EditorManager.createSite(EditorManager.java:604)
	at org.eclipse.ui.internal.EditorManager.openInternalEditor(EditorManager.java:666)
	at
org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager.java:459)
	at
org.eclipse.ui.internal.EditorManager.openEditorFromInput(EditorManager.java:333)
	at org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:424)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2051)
	at org.eclipse.ui.internal.WorkbenchPage.access$6(WorkbenchPage.java:1999)
	at org.eclipse.ui.internal.WorkbenchPage$9.run(WorkbenchPage.java:1986)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:1981)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:1882)
	at
org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:133)
	at
org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:111)
	at org.eclipse.jdt.internal.ui.actions.OpenTypeAction.run(OpenTypeAction.java:67)
	at org.eclipse.jdt.internal.ui.actions.OpenTypeAction.run(OpenTypeAction.java:80)
	at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:263)
	at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:207)
	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$5.handleEvent(ActionContributionItem.java:443)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2036)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1742)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1399)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:1382)
	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)
Comment 14 Philipe Mulet CLA 2003-06-17 05:32:07 EDT
What you are seeing is the behavior without the latest fix in. 
Closing/reopening the editor causes the secondary class cast issue (side-
effect).
Comment 15 Dani Megert CLA 2003-06-17 05:39:32 EDT
I have the newest (at least I have what Jerome asked me to verify).
André used JDT Core HEAD which shows the same problem.
Comment 16 Dani Megert CLA 2003-06-17 05:41:40 EDT
Note: it does not happen consistently. It worked but suddenly I could no longer
save the file. Same for André. No repeatable steps yet.
Comment 17 Philipe Mulet CLA 2003-06-17 07:15:11 EDT
Once it occurs, then nothing works any longer. The only remaining hole would be 
if someone did explicitly call #close() on a working copy (which doesn't happen 
in our code base). We will address this last issue, but it shouldn't be as 
critical as the implicit #close() occurring when cache is getting full.

Current thinking is that working copies should remain open until they are 
discarded. Indeed, a closed working copy may have trouble issuing reconcile 
fine-grain deltas (was assumed always open at this stage).
Need to investigate some more.
Comment 18 Jerome Lanneluc CLA 2003-06-17 09:07:59 EDT
Got the problem as well (with the patch). Still don't know how to reproduce the 
problem.
Comment 19 Philipe Mulet CLA 2003-06-17 09:56:10 EDT
We have now evidence it can still occur even with workaround.
Escaladating. Will need to resubmit.
Comment 20 Philipe Mulet CLA 2003-06-17 10:30:35 EDT
We suspect the remaining scenario is a concurrency issue around reconciliation. 
Reconciliation removes the info from the cache. If some other thread populates 
the working copy element during reconciliation, then it will not create a 
working copy element info.
Comment 21 DJ Houghton CLA 2003-06-17 11:01:33 EDT
*** Bug 39019 has been marked as a duplicate of this bug. ***
Comment 22 Jerome Lanneluc CLA 2003-06-18 07:20:59 EDT
Moved useCount and problemRequestor to another separate table (a table of 
PerWorkingCopyInfos). Elements in this table are updated independantly from the 
info of the working copy.

Also changed element cache to never close working copies until they are 
discarded.

Finally, got rid of WorkingCopyElementInfo. A working copy info is now a 
CompilationUnitInfo.
Comment 23 David Audel CLA 2003-07-17 12:25:48 EDT
Verified.