Bug 117622 - Test Failures in Reflection 1.5 World Delegate Implementation
Summary: Test Failures in Reflection 1.5 World Delegate Implementation
Status: VERIFIED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-22 22:17 EST by Ron Bodkin CLA
Modified: 2012-04-03 15:53 EDT (History)
0 users

See Also:


Attachments
test case (621 bytes, text/plain)
2005-11-22 22:18 EST, Ron Bodkin CLA
no flags Details
Patch to ReflectionBasedReferenceTypeDelegateTest that causes the problem (3.56 KB, patch)
2005-11-22 22:24 EST, Ron Bodkin CLA
no flags Details | Diff
Better test case that exposes three bugs in the Java 1.5 reflection code including the original one... (721 bytes, text/plain)
2005-11-22 22:26 EST, Ron Bodkin CLA
no flags Details
Patch to ReflectionBasedReferenceTypeDelegateTest that allows the tests to mostly work on a Java 1.5 (JRockIt!) VM... (3.30 KB, patch)
2005-11-22 22:27 EST, Ron Bodkin CLA
no flags Details | Diff
Patch to ReflectionBasedReferenceTypeDelegateTest that allows the tests to mostly work on a Java 1.5 (JRockIt!) VM... (3.51 KB, patch)
2005-11-22 22:45 EST, Ron Bodkin CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ron Bodkin CLA 2005-11-22 22:17:30 EST
See attached test case for the weaver5 project, to be placed in java5-testsrc/org/aspectj/weaver/reflect

Running it produces similar stack traces for all tests:

java.lang.StackOverflowError
	at java.lang.Class.forName(Ljava.lang.String;ZLjava.lang.ClassLoader;)Ljava.lang.Class;(Unknown Source)
	at org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegateFactory.createDelegate(ReflectionBasedReferenceTypeDelegateFactory.java:39)
	at org.aspectj.weaver.reflect.ReflectionWorld.resolveDelegate(ReflectionWorld.java:102)
	at org.aspectj.weaver.World.resolveToReferenceType(World.java:296)
	at org.aspectj.weaver.World.resolve(World.java:213)
	at org.aspectj.weaver.World.resolve(World.java:134)
	at org.aspectj.weaver.World.resolve(World.java:261)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromType(Java15ReflectionBasedReferenceTypeDelegate.java:270)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromType(Java15ReflectionBasedReferenceTypeDelegate.java:273)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromTypes(Java15ReflectionBasedReferenceTypeDelegate.java:312)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromType(Java15ReflectionBasedReferenceTypeDelegate.java:280)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getTypeVariables(Java15ReflectionBasedReferenceTypeDelegate.java:140)
	at org.aspectj.weaver.World.makeGenericTypeFrom(World.java:365)
	at org.aspectj.weaver.World.resolveToReferenceType(World.java:302)
	at org.aspectj.weaver.World.resolve(World.java:213)
	at org.aspectj.weaver.World.resolve(World.java:134)
	at org.aspectj.weaver.World.resolve(World.java:261)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromType(Java15ReflectionBasedReferenceTypeDelegate.java:270)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromType(Java15ReflectionBasedReferenceTypeDelegate.java:273)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromTypes(Java15ReflectionBasedReferenceTypeDelegate.java:312)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromType(Java15ReflectionBasedReferenceTypeDelegate.java:280)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getTypeVariables(Java15ReflectionBasedReferenceTypeDelegate.java:140)
	at org.aspectj.weaver.World.makeGenericTypeFrom(World.java:365)
	at org.aspectj.weaver.World.resolveToReferenceType(World.java:302)
	at org.aspectj.weaver.World.resolve(World.java:213)
	at org.aspectj.weaver.World.resolve(World.java:134)
Comment 1 Ron Bodkin CLA 2005-11-22 22:18:05 EST
Created attachment 30425 [details]
test case
Comment 2 Ron Bodkin CLA 2005-11-22 22:24:07 EST
Created attachment 30438 [details]
Patch to ReflectionBasedReferenceTypeDelegateTest that causes the problem

The offending line of code is 
		classType = world.resolve("java.lang.Class");

ok: I should have just submitted a separate test case with this specific problem...
Comment 3 Ron Bodkin CLA 2005-11-22 22:26:14 EST
Created attachment 30442 [details]
Better test case that exposes three bugs in the Java 1.5 reflection code including the original one...
Comment 4 Ron Bodkin CLA 2005-11-22 22:27:44 EST
Created attachment 30445 [details]
 Patch to ReflectionBasedReferenceTypeDelegateTest that allows the tests to mostly work on a Java 1.5 (JRockIt!) VM...
Comment 5 Ron Bodkin CLA 2005-11-22 22:32:31 EST
This test case is now failing with 4 distinct errors (when run with a JRockIt Java 1.5 VM inside Eclipse). I plan to work on these and will submit any fixes in separate bugs that depend on this one, to keep things organized. 

testResolveGeneric:

org.aspectj.weaver.BCException: Do not call nameToSignature with something that looks like a signature (descriptor): '[Ljava.lang.Object;'

	at org.aspectj.weaver.UnresolvedType.nameToSignature(UnresolvedType.java:729)
	at org.aspectj.weaver.UnresolvedType.forName(UnresolvedType.java:308)
	at org.aspectj.weaver.World.resolve(World.java:261)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.fromType(Java15ReflectionBasedReferenceTypeDelegate.java:270)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.createGenericMethodMember(Java15ReflectionBasedReferenceTypeDelegate.java:169)
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getDeclaredMethods(Java15ReflectionBasedReferenceTypeDelegate.java:154)
	at org.aspectj.weaver.ReferenceType.getDeclaredMethods(ReferenceType.java:398)
	at org.aspectj.weaver.reflect.TestJava5ReflectionBasedReferenceTypeDelegate.testResolveGeneric(TestJava5ReflectionBasedReferenceTypeDelegate.java:12)
	at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
	at jrockit.reflect.InitialMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
	at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

testGetDeclaredMethods:
java.lang.NullPointerException
	at org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegateTest.testGetDeclaredMethods(ReflectionBasedReferenceTypeDelegateTest.java:136)
	at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
	at jrockit.reflect.InitialMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
	at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

testGetAnnotations:
java.lang.UnsupportedOperationException: getAnnotations on Java15ReflectionBasedReferenceTypeDelegate is not implemented yet
	at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getAnnotations(Java15ReflectionBasedReferenceTypeDelegate.java:82)
	at org.aspectj.weaver.ReferenceType.getAnnotations(ReferenceType.java:120)
	at org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegateTest.testGetAnnotations(ReflectionBasedReferenceTypeDelegateTest.java:75)
	at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
	at jrockit.reflect.InitialMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
	at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Comment 6 Ron Bodkin CLA 2005-11-22 22:45:08 EST
Created attachment 30449 [details]
Patch to ReflectionBasedReferenceTypeDelegateTest that allows the tests to mostly work on a Java 1.5 (JRockIt!) VM...

I erroneously left out one line in pasting which generated one of the NPE's.
Comment 7 Ron Bodkin CLA 2005-11-22 23:08:17 EST
The patch in bug #117624 fixes the (not pasted in) test failure of an NPE in getSuperclass()

The test failure from testResolveGeneric is happening on the Collection.toArray() method, apparently because the return type of an array of generics is being treated as a Class but its name should be something like an array of generics. This code is complicated enough that I would need help to fix this bug. With the corrected original test case, testGetDeclaredMethods is producing this same error.

The test for getAnnotations can be fixed by delegated to super.getAnnotations() in the impl. Probably more tests for this are needed...
Comment 8 Andrew Clement CLA 2005-11-23 04:08:03 EST
I tried to put in the test from comment #3 (shame its not patch format) - its all a bit confusing Ron.  I put the test in - it fails to compile because world isnt exposed and findMethod doesnt exist.  So I discovered those in the patch in comment #2 which you had marked as being redundant now?  .... so.... basically I am putting in the test from comment #3 with the necessary bits hacked out of #2 - nothing else so far (testwise).
Comment 9 Andrew Clement CLA 2005-11-23 04:15:21 EST
So... the tests I put in dont fail as expected for me.  Presumably because the form of generics used in the jrockit vm differs from the sun one.

It would be far easier to get it working and tested consistently if we can write a generic type that looks the same as the failing one in jrockit and use it as a testcase on all VMs.  Do you know the *precise* generic signatures of the failing types and methods within them?

(I have fixed a problem to do with arrays and generic signatures a while ago - but it looks like I didnt catch all cases.)
Comment 10 Andrew Clement CLA 2005-11-23 11:30:18 EST
right - after some shuffling around (my fault) - I've recreated some of the problems here (not all).

1. nameToSignature()  - I've fixed this.
2. getSuperclass() problem - I've fixed this to return null as the superclass of Object, exactly the same as the other delegates do.
3. getAnnotations() - i made the same change Ron has - but marked it with a ?? to verify its right at some point.

4. getDeclaredMethods() blowing up.  This is complicated, I've recreated it but not fixed it yet.
5. The StackOverflow due to resolving java.lang.Class.  The test continues to just work for me.

I've put in Ron's two tests - but part of one of them is commented out until I get it working (getDeclaredMethods)

Just to confirm Ron - there aren't any problems I'm missing here?  (this bug has too many in !!)  And if you could try me changes to verify they fix the issues I claim, that would be very helpful.
Comment 11 Ron Bodkin CLA 2005-11-23 11:55:35 EST
Ok I see the first two bugs are fixed (thanks!). Now I'm seeing another old friend when I run my tests (this may be the same one that you noted you can recreate and are trying to fix, Andy). See stack trace below. I will work on recreating the infinite recursion bug and submit in a separate bug report (for sanity's sake).

java.lang.IllegalStateException: Can't ask to parameterize a member of a non-generic type
	at org.aspectj.weaver.ResolvedMemberImpl.parameterizedWith(ResolvedMemberImpl.java:605)
	at org.aspectj.weaver.ResolvedMemberImpl.parameterizedWith(ResolvedMemberImpl.java:590)
	at org.aspectj.weaver.ReferenceType.getDeclaredMethods(ReferenceType.java:402)
	at org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegateTest.testGetDeclaredMethods(ReflectionBasedReferenceTypeDelegateTest.java:134)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Comment 12 Ron Bodkin CLA 2005-11-23 12:10:02 EST
My test case just had a copy paste error. Here's the correct test case for the stack overflow on a Sun or JRockIt 1.5 VM:

	public void testResolveEnum() {
		//stack overflow
		world.resolve("java.lang.Enum");		
	}
Comment 13 Andrew Clement CLA 2005-11-25 04:39:47 EST
I've now fixed the other two problems:

4. getDeclaredMethods() blowing up.  
5. The StackOverflow resolving java.lang.Enum. 
Comment 14 Andrew Clement CLA 2005-11-26 11:55:43 EST
fixes available.
Comment 15 Ron Bodkin CLA 2005-11-28 01:20:26 EST
I have verified that all the problems are now fixed. Thanks!

I am wondering if this line of code shouldn't be in a finally block:

in Java15ReflectionBasedReferenceTypeDelegate.getTypeVariables() {
...
			this.getResolvedTypeX().getWorld().forgetTypeVariablesCurrentlyBeingProcessed(getBaseClass());
Comment 16 Andrew Clement CLA 2005-11-28 04:31:17 EST
I decided that if we go wrong in that processing we're screwed anyway, so trying to repair and recover isnt worth it...