Community
Participate
Working Groups
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
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)
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
We have no binding for the method invocation: X.<?, Object>create("", "") without reporting any error.
The problem seems to come from the fact that the wildcard without a bound returns null in the resolveType call without logging any error.
Added disabled regression test org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest._test1101()
Created attachment 57817 [details] Proposed fix
Looks good to me.
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.
Created attachment 57918 [details] New patch
Released for 3.3M5. Regression test enabled.
Verified for 3.3 M5 using build I20070205-0009
*** Bug 174724 has been marked as a duplicate of this bug. ***
Has this really been fixed in 3.3 M5? I could reproduce bug 174724 (marked as duplicate) using M5.
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)
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.