Bug 266582 - [1.5][compiler] AbortCompilation while decoding the type variable of an anonymous type
Summary: [1.5][compiler] AbortCompilation while decoding the type variable of an anony...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 246728 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-02-27 21:40 EST by Chris West (Faux) CLA
Modified: 2009-03-09 14:03 EDT (History)
5 users (show)

See Also:


Attachments
Project directory for testcase (1.57 KB, application/octet-stream)
2009-02-27 21:40 EST, Chris West (Faux) CLA
no flags Details
test case (2.12 KB, application/octet-stream)
2009-03-02 10:49 EST, Olivier Thomann CLA
no flags Details
Proposed patch (15.67 KB, patch)
2009-03-02 16:33 EST, Kent Johnson CLA
no flags Details | Diff
Proposed patch and testcase for 3.4.x (17.51 KB, patch)
2009-03-03 11:40 EST, Kent Johnson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris West (Faux) CLA 2009-02-27 21:40:32 EST
Created attachment 127069 [details]
Project directory for testcase

Occurs in both:
Version: 3.4.1 Build id: M20080911-1700
and:
Version: 3.5.0 Build id: I20081211-1908

Steps To Reproduce:
1. Open the attached project.
2. Attempt to find references of JohnsonException in class A.

More information:
-- Error Details --
Date: Sat Feb 28 02:33:25 GMT 2009
Message: An internal error occurred during: "Java Search".
Severity: Error
Plugin: org.eclipse.core.jobs
Session Data:
eclipse.buildId=I20081211-1908
java.version=1.6.0_12
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_GB
Command-line arguments:  -os win32 -ws win32 -arch x86_64

Exception Stack Trace:
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.availableMethods(BinaryTypeBinding.java:227)
	at org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:185)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1582)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1042)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1083)
	at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1215)
	at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:223)
	at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:506)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551)
	at org.eclipse.jdt.internal.ui.search.JavaSearchQuery.run(JavaSearchQuery.java:144)
	at org.eclipse.search2.internal.ui.InternalSearchUI$InternalSearchJob.run(InternalSearchUI.java:93)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Based on the stack this may be similar to bug 263451 and bug 250958, but neither have reproduction steps.  The attached testcase is 100% reliable here.

The summary of the code is.. (although, I'd recommend just looking at the attached project):
1) Custom exception class in package "foo".
2) Class which uses custom exception in doubly-nested anonymous inner class in "foo".
3) "foo" package exported as a jar.
4) Two copies of this jar (a.jar and b.jar) in the build path for another project, containing class A.

Having two copies of the same jar on the classpath happens with maven.
Comment 1 Frederic Fusier CLA 2009-03-02 05:50:17 EST
In this case, it seems there's a problem with the jar file(s) contents. The compiler detects an invalid method signature while reading class files and so aborts the compilation abruptly leaving the 'methods' field of the BinaryTypeBinding as null.

I've removed the a.jar and b.jar from the classpath, exported the source of the 'foo' folder in c.jar and d.jar files, put c.jar and d.jar files on the classpath and the search request finishes without any problem...

Search engine does not prevent itself against this kind of trouble, hence facing the NPE while trying to resolve during the match locating...
Comment 2 Frederic Fusier CLA 2009-03-02 06:07:33 EST
(In reply to comment #1)
> In this case, it seems there's a problem with the jar file(s) contents. The
> compiler detects an invalid method signature while reading class files and so
> aborts the compilation abruptly leaving the 'methods' field of the
> BinaryTypeBinding as null.
> 
> I've removed the a.jar and b.jar from the classpath, exported the source of the
> 'foo' folder in c.jar and d.jar files, put c.jar and d.jar files on the
> classpath and the search request finishes without any problem...
> 
> Search engine does not prevent itself against this kind of trouble, hence
> facing the NPE while trying to resolve during the match locating...
> 
This is not a problem with the jar file contents. The jar files I generated included sources although they should not to reproduce the problem.

So, it seems that the problem comes from the signature reader as I can see the class file contents in the Class File Editor...

Here's the stack I get when the AbortCompilation occurs:
TypeDeclaration.abort(int, CategorizedProblem) line: 72	
ProblemReporter(ProblemHandler).handle(int, String[], int, String[], int, int, int, ReferenceContext, CompilationResult) line: 157	
ProblemReporter.handle(int, String[], int, String[], int, int, int) line: 1928	
ProblemReporter.handle(int, String[], String[], int, int, int) line: 1991	
ProblemReporter.undefinedTypeVariableSignature(char[], ReferenceBinding) line: 6582	
LookupEnvironment.getTypeFromTypeSignature(SignatureWrapper, TypeVariableBinding[], ReferenceBinding, char[][][]) line: 1168	
LookupEnvironment.getTypeFromVariantTypeSignature(SignatureWrapper, TypeVariableBinding[], ReferenceBinding, ReferenceBinding, int, char[][][]) line: 1236	
LookupEnvironment.getTypeArgumentsFromSignature(SignatureWrapper, TypeVariableBinding[], ReferenceBinding, ReferenceBinding, char[][][]) line: 1023	
LookupEnvironment.getTypeFromTypeSignature(SignatureWrapper, TypeVariableBinding[], ReferenceBinding, char[][][]) line: 1185	
BinaryTypeBinding.cachePartsFrom(IBinaryType, boolean) line: 316	
LookupEnvironment.createBinaryTypeFrom(IBinaryType, PackageBinding, boolean, AccessRestriction) line: 635	
LookupEnvironment.cacheBinaryType(IBinaryType, boolean, AccessRestriction) line: 172	
LookupEnvironment.cacheBinaryType(IBinaryType, AccessRestriction) line: 159	
MatchLocator.cacheBinaryType(IType, IBinaryType) line: 392	
ClassFileMatchLocator.locateMatches(MatchLocator, ClassFile, IBinaryType) line: 179	

The SignatureWrapper argument of LookupEnvironment.getTypeArgumentsFromSignature
contains the following signature:
Ljava/lang/Object;Lfoo/Bar<TT;>; @ 30
Comment 3 Olivier Thomann CLA 2009-03-02 08:44:22 EST
(In reply to comment #1)
> In this case, it seems there's a problem with the jar file(s) contents. The
> compiler detects an invalid method signature while reading class files and so
> aborts the compilation abruptly leaving the 'methods' field of the
> BinaryTypeBinding as null.
This should be protected.
Comment 4 Olivier Thomann CLA 2009-03-02 09:24:56 EST
How the two jars were compiled ? Using the Eclipse compiler ?
Comment 5 Frederic Fusier CLA 2009-03-02 09:46:11 EST
(In reply to comment #4)
> How the two jars were compiled ? Using the Eclipse compiler ?
> 
I do not know for the reporter, but I generated mine using the Eclipse compiler with Export -> Jar file
Comment 6 Olivier Thomann CLA 2009-03-02 10:10:27 EST
The generic signature for the anonymous class is:
// Signature: Ljava/lang/Object;Lfoo/Bar<TT;>;


The Eclipse compiler and javac provides the same signature for the type.
It looks like we try to report an undefined type variable 'T' when decoding the super interface from the anonymous type binary .class file.

This looks more like a bug reading the .class file than an actual boggus signature inside the .class file itself.

Kent, could you please have a look ?

We might also want to make sure we don't leave methods and fields uninitialized.
Comment 7 Olivier Thomann CLA 2009-03-02 10:49:17 EST
Created attachment 127171 [details]
test case

Test case that is a zip file containing a java project with a class folder instead of jar file.
The abort compilation occurs when trying to match 'T' from the anonymous to the type variable defined in the enclosing type.

In this case, it should look for the enclosing method type variables and not the enclosing type.
Comment 8 Olivier Thomann CLA 2009-03-02 10:50:55 EST
The enclosing method can be retrieved looking at the enclosing method attribute of the enclosing type:
  Enclosing Method: #30  #32 foo/Bakkar.quuz()Lfoo/Bar;
Comment 9 Kent Johnson CLA 2009-03-02 11:18:46 EST
*** Bug 246728 has been marked as a duplicate of this bug. ***
Comment 10 Chris West (Faux) CLA 2009-03-02 13:08:23 EST
(In reply to comment #4)
> How the two jars were compiled ? Using the Eclipse compiler ?
> 

The jars in the test-case were produced with export->jar, yes, but the original problem occoured with maven produced jars with:
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) 64-Bit Server VM (build 11.2-b01, mixed mode)
Comment 11 Kent Johnson CLA 2009-03-02 16:33:15 EST
Created attachment 127232 [details]
Proposed patch
Comment 12 Frederic Fusier CLA 2009-03-03 04:00:30 EST
(In reply to comment #11)
> Created an attachment (id=127232) [details]
> Proposed patch
> 
Kent,

I've released _testBug266582() in JavaSearchBugsTest which fails on HEAD contents with the initially described NPE but passes with your patch...

You only need to remove the leading '_' to activate it when you're ready to release :-)
Comment 13 Philipe Mulet CLA 2009-03-03 09:24:44 EST
If the fix is simple enough, I'd like it in 3.4.x.
Comment 14 Kent Johnson CLA 2009-03-03 11:40:06 EST
Created attachment 127338 [details]
Proposed patch and testcase for 3.4.x
Comment 15 Kent Johnson CLA 2009-03-03 13:00:32 EST
Fix and test released into 3.4.x branch (post 3.4.2)
Comment 16 Kent Johnson CLA 2009-03-03 15:10:41 EST
Fix and test released for 3.5M6
Comment 17 Frederic Fusier CLA 2009-03-09 14:03:01 EDT
Verified for 3.5M6 using I20090309-0100