Bug 78275 - [recovery] NPE in GoToNextPreviousMemberAction with syntax error
Summary: [recovery] NPE in GoToNextPreviousMemberAction with syntax error
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.1 M4   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 78305 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-11-10 07:22 EST by Markus Keller CLA
Modified: 2004-12-14 10:39 EST (History)
4 users (show)

See Also:


Attachments
This patch seems to fix the problem... (994 bytes, patch)
2004-11-12 15:03 EST, Frederic Fusier CLA
no flags Details | Diff
Regression test add to CompilationUnitTests (2.08 KB, patch)
2004-11-12 15:26 EST, Frederic Fusier CLA
no flags Details | Diff
Correct patch (2.09 KB, text/plain)
2004-11-19 04:34 EST, David Audel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2004-11-10 07:22:47 EST
I200411090800

public class K {
	void a() {
/*press Ctrl+Shift+Down here*/	}
	}
	void m() {}
}

Error Nov 10, 2004 13:06:05.553 The command for the key you pressed failed
java.lang.NullPointerException
	at
org.eclipse.jdt.internal.ui.javaeditor.selectionactions.GoToNextPreviousMemberAction.firstOpeningBraceOffset(GoToNextPreviousMemberAction.java:224)
	at
org.eclipse.jdt.internal.ui.javaeditor.selectionactions.GoToNextPreviousMemberAction.getOffset(GoToNextPreviousMemberAction.java:214)
	at
org.eclipse.jdt.internal.ui.javaeditor.selectionactions.GoToNextPreviousMemberAction.addMemberOffsetList(GoToNextPreviousMemberAction.java:207)
	at
org.eclipse.jdt.internal.ui.javaeditor.selectionactions.GoToNextPreviousMemberAction.createOffsetArray(GoToNextPreviousMemberAction.java:200)
	at
org.eclipse.jdt.internal.ui.javaeditor.selectionactions.GoToNextPreviousMemberAction.getNewSelectionRange(GoToNextPreviousMemberAction.java:135)
	at
org.eclipse.jdt.internal.ui.javaeditor.selectionactions.GoToNextPreviousMemberAction.run(GoToNextPreviousMemberAction.java:102)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:988)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:188)
	at org.eclipse.ui.internal.commands.Command.execute(Command.java:130)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:445)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:724)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:767)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:536)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$2(WorkbenchKeyboard.java:479)
	at
org.eclipse.ui.internal.keys.WorkbenchKeyboard$1.handleEvent(WorkbenchKeyboard.java:221)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:752)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:817)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:827)
	at org.eclipse.swt.widgets.Control.traverse(Control.java:2696)
	at org.eclipse.swt.widgets.Control.translateTraversal(Control.java:2677)
	at org.eclipse.swt.widgets.Composite.translateTraversal(Composite.java:799)
	at org.eclipse.swt.widgets.Display.translateTraversal(Display.java:3241)
	at org.eclipse.swt.widgets.Display.filterMessage(Display.java:766)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2444)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1537)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1508)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:277)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:144)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:102)
	at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
	at java.lang.reflect.Method.invoke(Method.java:391)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
	at org.eclipse.core.launcher.Main.run(Main.java:704)
	at org.eclipse.core.launcher.Main.main(Main.java:688)
Comment 1 Dani Megert CLA 2004-11-10 13:37:28 EST
- iInitializer.getSourceRange() returns a SourceRange with offset=36, length=0
- the getSource() and getSourceRange() API say null is returned when there's no 
  source but since the parent has the source and getSourceRange() returns not null
  I'd expect to get non-null value for iInitializer.getSource()
Comment 2 Frederic Fusier CLA 2004-11-12 14:59:31 EST
This is a recovery problem. Start and end of initializer are not correctly
initialized when inserted to fix compilation issue.
Comment 3 Frederic Fusier CLA 2004-11-12 15:03:47 EST
Created attachment 15834 [details]
This patch seems to fix the problem...
Comment 4 Frederic Fusier CLA 2004-11-12 15:26:22 EST
Created attachment 15835 [details]
Regression test add to CompilationUnitTests
Comment 5 Frederic Fusier CLA 2004-11-14 16:14:12 EST
David,
Running JDT/Core tests shows that the fix is not valid. You're surely knows why
that source range length needs to be equals to 0 for the inserted initializer...
May you comment this change? Thx
Comment 6 Frederic Fusier CLA 2004-11-14 16:16:07 EST
Dani,
After further investigation, I'm not really convinced with your explanation.
The source range used by GoToNextPreviousMemberAction comes from private method
createSourceRange() which never returns null!
So, you do not rely on ISourceReference#getSourceRange() result to know whether
there's source or not...

I return this bug in your land as you really need to change implementation to
avoid this NPE in JDT/UI.
However, I agree that looking at implementation, Javadoc is not really accurate.
So, feel free to open a new bug to make us change either the Javadoc or the
behavior of ISourceReference#getSourceRange() method...
Comment 7 Dani Megert CLA 2004-11-15 06:00:04 EST
My explanation did not mention where the source range came from ;-) and I think
it's not relevant in this scenario. I commented what I saw in the debugger:

- I have an IType which has source (the action is only enabled in such a case)
- J Core gives me the (1) initializer (by calling IType.getInitializers())
- the initializer returns a source range but returns null for getSource()

Dirk and I would expect that if X (e.g. IType in our case) has source then all
the children have source as well (at least the empty string). getSourceRange()
already works like that.
Comment 8 Frederic Fusier CLA 2004-11-15 12:46:51 EST
So, if I've well understood, you're expecting that IInitializer#getSource() does
not return null in this case (like its parent in fact...).
Am i right?
Comment 9 Dani Megert CLA 2004-11-15 12:53:36 EST
Yes that is our expectation. Same as we expect getSourceRange() not to return
null when the parent already returned a source range.
Comment 10 David Audel CLA 2004-11-16 09:33:00 EST
This is a recovery problem but the fix inside comment 3 is not correct.
Comment 11 Frederic Fusier CLA 2004-11-16 09:44:28 EST
David, I already discarded my fix by myself in comment 5... ;-)
Comment 12 David Audel CLA 2004-11-16 09:52:39 EST
*** Bug 78305 has been marked as a duplicate of this bug. ***
Comment 13 Frederic Fusier CLA 2004-11-17 13:20:47 EST
I've released regression test in CompilationUnitTests by, of course, I've
desactivated it...
Comment 14 David Audel CLA 2004-11-19 04:34:35 EST
Created attachment 16009 [details]
Correct patch
Comment 15 David Audel CLA 2004-11-19 04:37:03 EST
Fixed and test added
  ASTConverterTestAST3_2#test0577()
  CompilationUnitTests#testBug78275()
Comment 16 Frederic Fusier CLA 2004-12-14 10:39:16 EST
Verified for 3.1 M4 using build I200412140800.