Bug 209623 - NullPointerexception on List.toArray + F3
Summary: NullPointerexception on List.toArray + F3
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.4 M4   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-13 07:31 EST by MH CLA
Modified: 2007-12-11 06:53 EST (History)
2 users (show)

See Also:


Attachments
Proposed fix (1.00 KB, patch)
2007-11-19 06:52 EST, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description MH CLA 2007-11-13 07:31:11 EST
Build ID: I20070625-1500

Steps To Reproduce:
1. Define a List like

final List<Mine> mines = new ArrayList<Mine>();

2. Call methot toArray():

mines.toArray(new Mine[mines.size()]);

3. Move cursor to "toArray" and press F3

=> Eclipse shows an error dialog "Problems opening an editor. See error log for more details"

The workspace/.metadata/.log will contain the following entries:

!ENTRY org.eclipse.jface.text 4 0 2007-11-13 13:26:31.850
!MESSAGE Unexpected runtime error while computing a text hover
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptBinaryMethod(SelectionRequestor.java:152)
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptMethod(SelectionRequestor.java:500)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.selectFrom(SelectionEngine.java:917)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:702)
	at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:155)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:340)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:334)
	at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getHoverInfo(AbstractJavaEditorTextHover.java:117)
	at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo(BestMatchHover.java:102)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo(JavaEditorTextHoverProxy.java:69)
	at org.eclipse.jface.text.TextViewerHoverManager$4.run(TextViewerHoverManager.java:165)

!ENTRY org.eclipse.jdt.ui 4 10001 2007-11-13 13:28:23.412
!MESSAGE Internal Error
!STACK 0
java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:350)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:495)
	at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:268)
	at org.eclipse.ui.internal.progress.ProgressManager$3.run(ProgressManager.java:909)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:944)
	at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:919)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter.performForkedCodeResolve(SelectionConverter.java:212)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolveForked(SelectionConverter.java:139)
	at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:134)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:272)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:244)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
	at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:475)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:429)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:165)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:470)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:821)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:879)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:568)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:510)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:126)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1141)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:937)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:947)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:975)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:971)
	at org.eclipse.swt.widgets.Widget.wmKeyDown(Widget.java:1570)
	at org.eclipse.swt.widgets.Control.WM_KEYDOWN(Control.java:3992)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3701)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:291)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4364)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2264)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3291)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
	at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
	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:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptBinaryMethod(SelectionRequestor.java:152)
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptMethod(SelectionRequestor.java:500)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.selectFrom(SelectionEngine.java:917)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:702)
	at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:155)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:340)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:334)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConverter.java:221)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter$1$CodeResolveRunnable.run(SelectionConverter.java:205)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Root exception:
java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptBinaryMethod(SelectionRequestor.java:152)
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptMethod(SelectionRequestor.java:500)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.selectFrom(SelectionEngine.java:917)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:702)
	at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:155)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:340)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:334)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConverter.java:221)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter$1$CodeResolveRunnable.run(SelectionConverter.java:205)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)

More information:
Java 1.6.0_03, Windows 2000 SP4

F3 on other API methods work, i.e. a new editor opens with the source showing the method.
Comment 1 David Audel CLA 2007-11-13 09:27:44 EST
I don't reproduce the bug with the following classes.

// p/Test.java
package p;

import java.util.ArrayList;
import java.util.List;

import q.Mine;

public class Test {
	void foo() {
		final List<Mine> mines = new ArrayList<Mine>();
		mines.toArray(new Mine[mines.size()]);
	}
}

// q/Mine.java
package q;

public class Mine {
}

Could you give me a more complete test case ?
I would need the file which contains the declaration of 'Mine' and the file which contains the declaration of 'mines' and the call to 'toArray'.
Comment 2 MH CLA 2007-11-13 14:22:36 EST
Well, the code I posted just was an examply. The real code is a quite big server application. At least, you need to add some elements into the list as the real code always has elements in it ... but this shouldn't have an effect on F3, should it?

Can't you see something from the stack traces I posted? From the source of the corresponding eclipse files:

java.lang.NullPointerException
        at
org.eclipse.jdt.internal.core.SelectionRequestor.acceptBinaryMethod(SelectionRequestor.java:152)

?
Comment 3 David Audel CLA 2007-11-14 06:43:57 EST
By looking the stacktrace i can only deduce a partial fix. This partial fix would avoid the NPE but would not fix the real problem.

The problem is in SelectionRequestor.acceptBinaryMethod():

IMethod[] methods = type.findMethods(method);
if (methods.length > 1) {

'methods' is null and should not. The partial fix would be to add only a null check but the real problem is that 'methods' shouldn't be null.


If you can't give me the full source that cause the bug could you try to build a smaller test case that reproduce the bug ?
Comment 4 David Audel CLA 2007-11-14 06:44:26 EST
Do you reproduce the bug with the following test case ?

// p/Test.java
package p;

import java.util.ArrayList;
import java.util.List;

import ???.Mine; // replace ??? with the right package name

public class Test {
        void foo() {
                final List<Mine> mines = new ArrayList<Mine>();
                mines.toArray(new Mine[mines.size()]);
        }
}
Comment 5 MH CLA 2007-11-16 03:45:33 EST
Hm, nope - I can't reproduce it... even in the original case where I got this error on the day I posted this bug report. Too bad ... :-(

I guess, this bug will be closed as "won't fix" or "worksforme" ... ?
Comment 6 David Audel CLA 2007-11-16 04:15:06 EST
(In reply to comment #5)
> 
> I guess, this bug will be closed as "won't fix" or "worksforme" ... ?
> 
No, the partial fix is sufficient to avoid the NPE. So even if the behavior isn't perfect, it will be better than now.
Comment 7 David Audel CLA 2007-11-19 06:52:02 EST
Created attachment 83226 [details]
Proposed fix

This fix add only a null check
Comment 8 David Audel CLA 2007-11-19 06:54:53 EST
Released for 3.4M4.
Comment 9 Eric Jodet CLA 2007-12-11 06:53:53 EST
Verified in the code for 3.4 M4 using build I20071210-1800