Bug 97108

Summary: [1.5][compiler] NullPointerException encountered while running Java Builder
Product: [Eclipse Project] JDT Reporter: Elmar Sonnenschein <develop>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: fast.jack
Version: 3.1   
Target Milestone: 3.1 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
ZIP containing Eclipse 3.1RC1 project to reproduce the problem
none
Batch compiler test case that reproduces the problem none

Description Elmar Sonnenschein CLA 2005-05-28 05:04:29 EDT
One of my sourcecode files in a Java 5.0 project causes the eclipse compiler to
stop compiling with an "internal compiler error" - but only if that file is
changed and compiled alone. If I recompile the whole project afterwards (or
change the file again which causes eclipse to do a full build in this case) it
compiles without problems. Unfortunately I cannot extract a single sourcecode
example to reproduce the problem because it seems that it is caused by the
overall project and/or class structure. Below you'll find the stack trace from
the error log.

java.lang.NullPointerException
at
org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.enclosingType(ParameterizedTypeBinding.java:256)
at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createRawType(LookupEnvironment.java:497)
at
org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.swapUnresolved(ParameterizedTypeBinding.java:873)
at
org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.setResolvedType(UnresolvedReferenceBinding.java:75)
at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:405)
at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:393)
at org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:190)
at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:99)
at
org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:43)
at
org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveUnresolvedType(BinaryTypeBinding.java:92)
at
org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.memberTypes(BinaryTypeBinding.java:722)
at
org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.memberTypes(ParameterizedTypeBinding.java:671)
at
org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.getMemberType(ParameterizedTypeBinding.java:457)
at org.eclipse.jdt.internal.compiler.lookup.Scope.findMemberType(Scope.java:998)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:2393)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2237)
at
org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(SingleTypeReference.java:39)
at
org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:124)
at
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypeFor(SourceTypeBinding.java:1176)
at
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.fields(SourceTypeBinding.java:630)
at
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:616)
at
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:393)
at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:497)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:329)
at
org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:240)
at
org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:190)
at
org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:114)
at
org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:227)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:155)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:593)
at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1038)
at org.eclipse.core.runtime.Platform.run(Platform.java:775)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:168)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:202)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:231)
at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1038)
at org.eclipse.core.runtime.Platform.run(Platform.java:775)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:234)
at
org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:253)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:282)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:139)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:200)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:67)
Comment 1 Elmar Sonnenschein CLA 2005-05-28 05:08:08 EDT
ps: Tested with 3.1RC1
Comment 2 Philipe Mulet CLA 2005-05-28 08:56:02 EDT
Please provide steps to reproduce, then reopen.
Comment 3 Philipe Mulet CLA 2005-05-28 18:41:30 EDT
A parameterized member type cannot have a type not associated with an enclosing
type. Suspecting the type of param type to not be a generic type, but rather
another parameterized type. Would need a testcase to find offending scenario.
Comment 4 Elmar Sonnenschein CLA 2005-05-29 05:37:27 EDT
Created attachment 21934 [details]
ZIP containing Eclipse 3.1RC1 project to reproduce the problem
Comment 5 Elmar Sonnenschein CLA 2005-05-29 05:47:44 EDT
Ok, I took the code apart and isolated the problem. The attachment contains a
stripped down Eclipse project that should allow you to reproduce the problem.
Changing and then recompiling the "RecordStringTransform.java" sourcecode (or
that of a base class) causes the mentioned compiler error on my system on each
second compilation.

While digging into this I also found a way to prevent the compiler error. You'll
find the necessary change in the "StringTransform.java" sourcecode, preceded
with a comment containing "FIX:". It is a declaration that misses a generic type
declaration (the project had been converted to JDK 5.0). But as far as I can see
the code is not wrong without the declaration but just using the raw type.
Comment 6 Philipe Mulet CLA 2005-05-29 15:15:18 EDT
Thank you much.
Comment 7 Maxime Daniel CLA 2005-06-01 13:38:18 EDT
Created attachment 22182 [details]
Batch compiler test case that reproduces the problem

_test34 shows that the suggested workaround works
_test35 reproduces the problem on a small code base
_test36 shows that simplistic attempts to simplify _test35 fail to reproduce
the problem
Comment 8 Philipe Mulet CLA 2005-06-04 08:59:47 EDT
Problem came from lazy enclosing type resolution. When needing the enclosing
type (during UnresolvedReferenceBinding.setResolvedType(...)), the binary type
didn't yet know it had any. 

Moved enclosingType init in BinaryTypeBinding constructor, and ensured all
creator of ParameterizedTypeBinding specify an enclosing type if any (it is no
longer ok to pass null, and rely on resolution later on, since the enclosingType
is a criteria for reusing the binding in the cache).

Added GenericTypeTest#test711-712 (adapted from proposed batch test 34&35).
Comment 9 Philipe Mulet CLA 2005-06-04 09:00:56 EDT
forgot to reassign
Comment 10 Philipe Mulet CLA 2005-06-04 09:01:25 EDT
fixed
Comment 11 Philipe Mulet CLA 2005-06-05 11:01:43 EDT
*** Bug 98232 has been marked as a duplicate of this bug. ***
Comment 12 Frederic Fusier CLA 2005-06-07 10:16:47 EDT
Verified for 3.1 RC2 using build N20050607-0010 + JDT/Core HEAD
Comment 13 Jerome Lanneluc CLA 2005-06-10 11:14:35 EDT
Verified with I20050610-0010