Bug 83499 - NPE when restoring ITypeBinding from key
Summary: NPE when restoring ITypeBinding from key
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-23 08:32 EST by Dirk Baeumer CLA
Modified: 2005-02-15 11:51 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2005-01-23 08:32:37 EST
Restoring a ITypeBinding form key Ljava/util/Vector<-TT;>; result in a class
cast exception. The key was provided by a binding generated from the following
declaration: java.util.Vector<? super T extends java.lang.Object>

Thread [main] (Suspended (exception ClassCastException))
	BindingKey.getCompilerBinding(CompilationUnitDeclaration) line: 165
	BindingKey.getCompilerBinding() line: 211
	CompilationUnitResolver.resolve(ICompilationUnit[], String[], ASTRequestor,
int, Map, WorkingCopyOwner, IProgressMonitor) line: 667
	CompilationUnitResolver.resolve(ICompilationUnit[], String[], ASTRequestor,
int, Map, IJavaProject, WorkingCopyOwner, IProgressMonitor) line: 436
	ASTParser.createASTs(ICompilationUnit[], String[], ASTRequestor,
IProgressMonitor) line: 651
	TypeEnvironment.createTypeBindings(TType[], IJavaProject) line: 103
	TypeEnvironmentTests.performGenericAssignmentTest() line: 196
	TypeEnvironmentTests.testStandardAssignments() line: 204
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available
[native method]
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
	Method.invoke(Object, Object[]) line: 324
	TypeEnvironmentTests(TestCase).runTest() line: 154
	TypeEnvironmentTests(TestCase).runBare() line: 127
	TestResult$1.protect() line: 106
	TestResult.runProtected(Test, Protectable) line: 124
	TestResult.run(TestCase) line: 109
	TypeEnvironmentTests(TestCase).run(TestResult) line: 118
	TestSuite.runTest(Test, TestResult) line: 208
	TestSuite.run(TestResult) line: 203
	TypeEnvironmentTests$MyTestSetup(TestDecorator).basicRun(TestResult) line: 22
	TestSetup$1.protect() line: 19
	TestResult.runProtected(Test, Protectable) line: 124
	TypeEnvironmentTests$MyTestSetup(TestSetup).run(TestResult) line: 23
	RemotePluginTestRunner(RemoteTestRunner).runTests(String[], String) line: 474
	RemotePluginTestRunner(RemoteTestRunner).run() line: 342
	RemotePluginTestRunner.main(String[]) line: 36
	UITestApplication$1.run() line: 110
	RunnableLock.run() line: 35
	UISynchronizer(Synchronizer).runAsyncMessages(boolean) line: 118
	Display.runAsyncMessages(boolean) line: 2787
	Display.readAndDispatch() line: 2458
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 1575
	Workbench.runUI() line: 1541
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 287
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 144
	IDEApplication.run(Object) line: 102
	UITestApplication.run(Object) line: 39
	PlatformActivator$1.run(Object) line: 220
	EclipseStarter.run(Object) line: 274
	EclipseStarter.run(String[], Runnable) line: 129
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available
[native method]
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
	Method.invoke(Object, Object[]) line: 324
	Main.basicRun(String[]) line: 185
	Main.run(String[]) line: 684
	Main.main(String[]) line: 668
Comment 1 Dirk Baeumer CLA 2005-01-23 08:33:14 EST
Jerome, I hope it is OK to assign PRs like this directly to you.
Comment 2 Jerome Lanneluc CLA 2005-01-24 04:51:21 EST
I cannot reproduce. Also java.util.Vector<? super T extends java.lang.Object> is
not a valid declaration. Do you have more details ?
Comment 3 Dirk Baeumer CLA 2005-01-24 05:18:39 EST
I simply took the toString() output. The correct declaration looks like this:

class A<T> {
   Vector<? extends T> vector;
}

Comment 4 Jerome Lanneluc CLA 2005-01-24 07:28:50 EST
So is it:
- java.util.Vector<? super T extends java.lang.Object> ?
- Vector<? extends T> ?
- something else ? :-)

Can I assume that java.util.Vector is in binary form ?
Comment 5 Dirk Baeumer CLA 2005-01-24 09:28:46 EST
- vector is in binary form
- the fetched the key from the type binding for the field vector in the
  example above. So it is 
  
  Vector<? extends T> 

  where T is a type argument with a default bound of Object.
  
Comment 6 Jerome Lanneluc CLA 2005-01-24 10:59:18 EST
For Vector<? extends T>, the binding key is "Ljava/lang/Vector<+TT;>;" (and not
"Ljava/util/Vector<-TT;>;"). However I still don't get a ClassCastException
trying to restore "Ljava/lang/Vector<+TT;>;". I assume you used v_532 of JDT
Core. Did I assume correctly ? If I did, I don't see how a ClassCastException
can be thrown.

However I get an invalid binding (the bound of the wildcard binding is null). I
will fix that.
Comment 7 Dirk Baeumer CLA 2005-01-24 12:01:24 EST
Sorry, I meant Vector<? super T>

I will check which version of JDT/Core I use
Comment 8 Jerome Lanneluc CLA 2005-01-25 07:05:22 EST
Note that the format of the binding key has now changed. The null bound problem
in the wildcard binding is now fixed. Please try with org.eclipse.jdt.core
v_532c or greater. If you don't get a ClassCastException with this version, let
me know and I will close this bug.
Comment 9 Dirk Baeumer CLA 2005-01-25 13:16:37 EST
Jerome, 

I retested it with JDT/Core from todays integration build an now I get an NPE
when restoring Ljava/util/Vector<+Lgeneric/TestStandardAssignments<TT;TU;>;:TT;>;

You can test it using the test case TypeEnvironmentTests from
jdt.ui.test.refactoring.

You have to uncomment the code:

/*
ITypeBinding[] restoredBindings= TypeEnvironment.createTypeBindings(types,
RefactoringTestSetup.getProject());
assertEquals("Not same length", restoredBindings.length, bindings.length);
for (int i= 0; i < restoredBindings.length; i++) {
	assertTrue("Not same binding", bindings[i].isEqualTo(restoredBindings[i]));
}
*/

Running this reveals a second problem. The key 

Ljava/util/List<+[Ljava/lang/Object;>; 

obtained from the binding 

public interface List<? extends java.lang.Object[]>
	extends java.lang.Object
	implements : Collection<? extends java.lang.Object[]>NULL FIELDSNULL METHODS

will be restored to

public interface List<? extends java.lang.Object[][]>
	extends NULL TYPENULL SUPERINTERFACESNULL FIELDSNULL METHODS





Comment 10 Jerome Lanneluc CLA 2005-01-26 08:04:29 EST
I don't see any commented code in TypeEnvironmentTests v200501250800.
Also what is the NPE that you're getting.
Comment 11 Dirk Baeumer CLA 2005-01-26 08:45:24 EST
You have to take the version from HEAD. I released it yesterday evening.

The stack trace is:

Thread [main] (Suspended (exception NullPointerException))
	BindingKey.getCompilationUnitDeclaration() line: 401
	BindingKey.getCompilerBinding() line: 465
	BindingKey.getWildCardBinding(ReferenceBinding, int) line: 674
	BindingKey.getParameterizedTypeBinding(ReferenceBinding, ReferenceBinding)
line: 584
	BindingKey.getCompilerBinding(CompilationUnitDeclaration) line: 427
	BindingKey.getCompilerBinding() line: 469
	CompilationUnitResolver.resolve(ICompilationUnit[], String[], ASTRequestor,
int, Map, WorkingCopyOwner, IProgressMonitor) line: 674
	CompilationUnitResolver.resolve(ICompilationUnit[], String[], ASTRequestor,
int, Map, IJavaProject, WorkingCopyOwner, IProgressMonitor) line: 443
	ASTParser.createASTs(ICompilationUnit[], String[], ASTRequestor,
IProgressMonitor) line: 651
	TypeEnvironment.createTypeBindings(TType[], IJavaProject) line: 104
	TypeEnvironmentTests.testBindings(ITypeBinding[]) line: 227
	TypeEnvironmentTests.performGenericAssignmentTest() line: 196
	TypeEnvironmentTests.testStandardAssignments() line: 268
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available
[native method]
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
	Method.invoke(Object, Object[]) line: 324
	TypeEnvironmentTests(TestCase).runTest() line: 154
	TypeEnvironmentTests(TestCase).runBare() line: 127
	1.protect() line: 106
	TestResult.runProtected(Test, Protectable) line: 124
	TestResult.run(TestCase) line: 109
	TypeEnvironmentTests(TestCase).run(TestResult) line: 118
	TestSuite.runTest(Test, TestResult) line: 208
	TestSuite.run(TestResult) line: 203
	MyTestSetup(TestDecorator).basicRun(TestResult) line: 22
	1.protect() line: 19
	TestResult.runProtected(Test, Protectable) line: 124
	MyTestSetup(TestSetup).run(TestResult) line: 23
	RemotePluginTestRunner(RemoteTestRunner).runTests(String[], String) line: 474
	RemotePluginTestRunner(RemoteTestRunner).run() line: 342
	RemotePluginTestRunner.main(String[]) line: 36
	1.run() line: 110
	RunnableLock.run() line: 35
	UISynchronizer(Synchronizer).runAsyncMessages(boolean) line: 118
	Display.runAsyncMessages(boolean) line: 2787
	Display.readAndDispatch() line: 2458
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 1575
	Workbench.runUI() line: 1541
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 287
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 144
	IDEApplication.run(Object) line: 102
	UITestApplication.run(Object) line: 39
	1.run(Object) line: 220
	EclipseStarter.run(Object) line: 274
	EclipseStarter.run(String[], Runnable) line: 129
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available
[native method]
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
	Method.invoke(Object, Object[]) line: 324
	Main.basicRun(String[]) line: 255
	Main.run(String[]) line: 811
	Main.main(String[]) line: 795

The variable is

binding= SourceTypeBinding  (id=88)
	compoundName= char[2][]  (id=103)
	constantPoolName= char[31]  (id=104)
	fields= FieldBinding[63]  (id=105)
	fileName= char[66]  (id=106)
	fPackage= PackageBinding  (id=107)
	genericReferenceTypeSignature= char[41]  (id=109)
	id= 2147483647
	memberTypes= ReferenceBinding[0]  (id=110)
	methods= MethodBinding[1]  (id=111)
	modifiers= 1073741825
	scope= null
	signature= char[33]  (id=114)
	sourceName= char[23]  (id=115)
	superclass= BinaryTypeBinding  (id=116)
	superInterfaces= ReferenceBinding[0]  (id=118)
	synthetics= null
	tagBits= 8589952768
	typeVariables= TypeVariableBinding[2]  (id=119)
Comment 12 Jerome Lanneluc CLA 2005-01-26 09:12:55 EST
Sorry, this doesn't compile. I'll have to wait for a stable version.
Comment 13 Jerome Lanneluc CLA 2005-02-03 13:03:06 EST
Fixed NPE problem in BindingKeyResolver#getCompilationUnit() by returning null
if the scope is null.
Added regression test BatchASTCreationTests#test045().
Comment 14 Jerome Lanneluc CLA 2005-02-04 09:13:15 EST
Added regression test BatchASTCreationTests#test050() to ensure that
"java/util/List<+[Ljava/lang/Object;>;" is correctly restored.
Comment 15 David Audel CLA 2005-02-15 11:51:14 EST
Verified in I20050214-0927