Bug 80957

Summary: NPE using code assist for unresolved type
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Olivier Thomann CLA 2004-12-14 12:40:01 EST
Using 200412140800, I got the following exception:

java.lang.NullPointerException
	at
org.eclipse.jdt.internal.codeassist.SelectionEngine.selectFrom(SelectionEngine.java:795)
	at
org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:714)
	at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:140)
	at
org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:300)
	at
org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:294)
	at
org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector.detectHyperlinks(JavaElementHyperlinkDetector.java:73)
	at
org.eclipse.jface.text.hyperlink.HyperlinkManager.findHyperlinks(HyperlinkManager.java:235)
	at
org.eclipse.jface.text.hyperlink.HyperlinkManager.mouseMove(HyperlinkManager.java:422)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:144)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:833)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2803)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2448)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1569)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1540)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:285)
	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:220)
	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:684)
	at org.eclipse.core.launcher.Main.main(Main.java:668)


Steps to reproduce:

1) Create a new Java project
2) Set the compiler compliance to 1.5
3) Create a new compilation unit that contains:
public class ShortcutIfElse {

    public ShortcutIfElse() { }
	
    public Integer[] getTypes() {
        List<Integer> list = new ArrayList<Integer>();
        return list == null 
            ? new Integer[0] 
            : list.toArray(new Integer[list.size()]);
    }

    public static void main(String[] args) {
        Class clazz = null;
        try {
            clazz = Class.forName("ShortcutIfElse");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
ArrayList and List are reported as errors.
3) Code assist behind ArrayList to add a import.
4) Do the same for List and you should get the NPE.
Comment 1 Olivier Thomann CLA 2004-12-14 14:15:44 EST
Null check added.
Fixed and released in HEAD.
Regression test added in org.eclipse.jdt.core.tests.model.ResolveTests_1_5.test0086
Comment 2 Olivier Thomann CLA 2004-12-14 14:16:08 EST
Reopen to assign
Comment 3 Olivier Thomann CLA 2004-12-14 14:17:00 EST
Null check added.
Fixed and released in HEAD.
Regression test added in org.eclipse.jdt.core.tests.model.ResolveTests_1_5.test0086
Comment 4 Olivier Thomann CLA 2004-12-14 23:30:12 EST
Verified in 200412141600