Bug 172189 - [1.5][compiler] NPE in CompilationUnitProblemFinder.process with explicit wildcard invocation
Summary: [1.5][compiler] NPE in CompilationUnitProblemFinder.process with explicit wil...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 174724 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-01-30 11:51 EST by Alexis Lauthier CLA
Modified: 2007-02-20 10:50 EST (History)
3 users (show)

See Also:


Attachments
Proposed fix (3.79 KB, patch)
2007-01-30 13:18 EST, Olivier Thomann CLA
no flags Details | Diff
New patch (3.92 KB, patch)
2007-01-31 10:55 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexis Lauthier CLA 2007-01-30 11:51:53 EST
Eclipse 3.3M4 I20061214-1445, Sun 1.6.0-rc-b104, Win XP SP2

Internal compiler error while compiling the following class:

import java.util.*;

public final class Pair<A, B> {

    public A a;
    public B b;

    public Pair(A pa, B pb) {
        a = pa;
        b = pb;
    }

    public static <A, B> Pair<A, B> create(A pa, B pb) {
        return new Pair<A, B>(pa, pb);
    }

    public static void main(String[] args) {
        List<Pair<String, Object>> list = new ArrayList<Pair<String,Object>>();
        list.add(Pair.<?, Object>create("", ""));
    }
}

If the ? wildcard is replaced with the correct type (String) it compiles without problem.


.log information:

!ENTRY org.eclipse.core.resources 2 75 2007-01-30 17:20:34.421
!MESSAGE Errors during build.
!SUBENTRY 1 org.eclipse.jdt.core 2 75 2007-01-30 17:20:34.421
!MESSAGE Errors running builder 'Java Builder' on project 'Bug'.
!SUBENTRY 1 org.eclipse.jdt.core 2 75 2007-01-30 17:20:34.421
!MESSAGE java.lang.NullPointerException encountered while running Java Builder.
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.jdt.core 4 4 2007-01-30 17:20:35.359
!MESSAGE Exception occurred during problem detection:
----------------------------------- SOURCE BEGIN -------------------------------------
import java.util.*;

public final class Pair<A, B> {

    public A a;
    public B b;

    public Pair(A pa, B pb) {
        a = pa;
        b = pb;
    }

    public static <A, B> Pair<A, B> create(A pa, B pb) {
        return new Pair<A, B>(pa, pb);
    }

    public static void main(String[] args) {
        List<Pair<String, Object>> list = new ArrayList<Pair<String,Object>>();
        list.add(Pair.<?, Object>create("", ""));
    }
}

----------------------------------- SOURCE END -------------------------------------
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.jdt.ui 4 0 2007-01-30 17:20:35.359
!MESSAGE Error in JDT Core during reconcile
!STACK 1
Java Model Exception: java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:227)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:249)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:166)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:85)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:720)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:779)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1147)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:97)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:82)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:145)
	at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:86)
	at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:96)
	at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:75)
	at org.eclipse.jdt.internal.ui.text.JavaReconciler.process(JavaReconciler.java:343)
	at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:204)
org.eclipse.jdt.core.JavaModelException[1005]: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
!SUBENTRY 1 org.eclipse.jdt.core 4 1005 2007-01-30 17:20:35.359
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
Comment 1 Olivier Thomann CLA 2007-01-30 12:19:38 EST
This is an invalid case that is not propertly reported.
When simply trying to compile the code, we get:
Internal compiler error
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:45)
	at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:54)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.analyseCode(MethodDeclaration.java:90)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:668)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:253)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:107)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:621)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:391)
	at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:3024)
	at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1324)
	at org.eclipse.jdt.core.tools.compiler.Compile.main(Compile.java:86)
Comment 2 Olivier Thomann CLA 2007-01-30 12:20:15 EST
javac 1.6 u1_b03 reports:
X.java:19: illegal start of type
        list.add(X.<?, Object>create("", ""));
                    ^
X.java:19: illegal start of expression
        list.add(X.<?, Object>create("", ""));
                     ^
2 errors
Comment 3 Olivier Thomann CLA 2007-01-30 12:21:52 EST
We have no binding for the method invocation:
X.<?, Object>create("", "")
without reporting any error.
Comment 4 Olivier Thomann CLA 2007-01-30 12:28:30 EST
The problem seems to come from the fact that the wildcard without a bound returns null in the resolveType call without logging any error.
Comment 5 Olivier Thomann CLA 2007-01-30 12:46:56 EST
Added disabled regression test org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest._test1101()
Comment 6 Olivier Thomann CLA 2007-01-30 13:18:50 EST
Created attachment 57817 [details]
Proposed fix
Comment 7 Philipe Mulet CLA 2007-01-31 04:51:13 EST
Looks good to me.
Comment 8 Olivier Thomann CLA 2007-01-31 10:45:39 EST
I missed a case with the first fix where the parameterized type cannot be resolved. In this case, we ended up reporting too many errors.
I propose to move the check inside the message send class.
See my second proposal.
Comment 9 Olivier Thomann CLA 2007-01-31 10:55:01 EST
Created attachment 57918 [details]
New patch
Comment 10 Olivier Thomann CLA 2007-01-31 14:32:18 EST
Released for 3.3M5.
Regression test enabled.
Comment 11 Eric Jodet CLA 2007-02-06 07:47:11 EST
Verified for 3.3 M5 using build I20070205-0009
Comment 12 Olivier Thomann CLA 2007-02-20 00:22:38 EST
*** Bug 174724 has been marked as a duplicate of this bug. ***
Comment 13 Rafael Chaves CLA 2007-02-20 09:28:36 EST
Has this really been fixed in 3.3 M5? I could reproduce bug 174724 (marked as duplicate) using M5.
Comment 14 Olivier Thomann CLA 2007-02-20 10:25:59 EST
Your test case from bug 174724 compiles fine using M5.

d:\tests_sources>java -jar org.eclipse.jdt.core_3.3.0.v_735.jar X.java -1.5
----------
1. WARNING in X.java (at line 3)
        Class foo = Class.<? extends Object>forName(Integer.class.getName());
        ^^^^^
Class is a raw type. References to generic type Class<T> should be parameterized
----------
2. ERROR in X.java (at line 3)
        Class foo = Class.<? extends Object>forName(Integer.class.getName());
                           ^^^^^^^^^^^^^^^^
Wildcard is not allowed at this location
----------
2 problems (1 error, 1 warning)
Comment 15 Rafael Chaves CLA 2007-02-20 10:50:47 EST
Never mind, I was actually using M4. I was reading the build number from the log file, and I had inadvertently been running M5 and M4 on the same workspace (the log file had some sessions describing the M5 build, and others the M4 build). Should use the About dialog box next time.