Community
Participate
Working Groups
Compiled my project using aspectj 1.5 under Windows XPSP2, java 1.5.0_05, using jboss 4.03 Inside a jsp page I included an import of the compiled class file using generics. the error i receive is below Generated servlet error: [javac] C:\jboss\server\default\work\jboss.web\localhost\backstop\org\apache\jsp\WEB_002dINF\struts\relationshipSummary_jsp.java:20: cannot access com.backstopsolutions.common.utils.Pair Generated servlet error: [javac] bad class file: C:\jboss\server\default\tmp\deploy\tmp17190backstop.ear-contents\backstop-core.jar(com/backstopsolutions/common/utils/Pair.class) [javac] undeclared type variable: S [javac] Please remove or make sure it appears in the correct subdirectory of the classpath. [javac] import com.backstopsolutions.common.utils.Pair; [javac] ^ [javac] 1 error I have test files, but I don't see anywhere on the form to submit them. Please email me and I can send you the test files.
Created attachment 34081 [details] the attachment is a tar archived file containing a test case ot reproduce the bug unzip the file, change to the directory javac Test.java Test.java:2: cannot access com.backstopsolutions.common.utils.Pair bad class file: .\com\backstopsolutions\common\utils\Pair.class undeclared type variable: S Please remove or make sure it appears in the correct subdirectory of the classpath. import com.backstopsolutions.common.utils.Pair; ^ 1 error The Pair.class file was compiled with ajc version 1.5 If you have any questions, please email me
note: compiled the project using iajc ant task
This looks exactly like an old JDT bug (bug 101794) - the error messages are identical and the scenario is even very similar (JSPs, jdt compiler and javac). Can you confirm exactly which version of AspectJ was used to build the Pair class. Do ajc -version and see what you get - I get: C:\foo\aspectjTest>ajc -version AspectJ Compiler 1.5.0 built on Tuesday Dec 20, 2005 at 12:05:54 GMT
(In reply to comment #3) > This looks exactly like an old JDT bug (bug 101794) - the error messages are > identical and the scenario is even very similar (JSPs, jdt compiler and javac). > Can you confirm exactly which version of AspectJ was used to build the Pair > class. Do ajc -version and see what you get - I get: > > C:\foo\aspectjTest>ajc -version > AspectJ Compiler 1.5.0 built on Tuesday Dec 20, 2005 at 12:05:54 GMT > It was compiled using the exact same version: C:\aspectj1.5\bin>ajc -version AspectJ Compiler 1.5.0 built on Tuesday Dec 20, 2005 at 12:05:54 GMT -Jeff
Recreated as follows. Unzip the attached tar then renamed the Pair.java file to Pair.java.src (so the compiler doesn't recompile it...) then javac Test.java C:\aspectj1.5-dev\pr126355\aspectjTest>javac Test.java Test.java:3: cannot access com.backstopsolutions.common.utils.Pair bad class file: .\com\backstopsolutions\common\utils\Pair.class undeclared type variable: S Please remove or make sure it appears in the correct subdirectory of the classpath. import com.backstopsolutions.common.utils.Pair; ^ 1 error If I then remove Pair.class, rename Pair.java.src to Pair.java and rerun the javac command - it works fine. Pair.class is rebuilt. I then removed Pair.class again and recompiled Pair.java using AspectJ 1.5, this worked but produced a class file of a completely different size to the original. The entirely different size is because the original Pair.class included in the attached tar file is affected by an aspect 'IdempotentCache' and as I don't have that aspect, I can't rebuild Pair to verify the latest compiler is still having this problem. Is it possible to attach the IdempotentCache aspect ?
Created attachment 42192 [details] IdempotentCache related source files the attachment contains the IdempotentCache.aj and 2 source files needed by the aspect. if you need any other files, just let me know. thanks a bunch, Jeff
great! thanks for that - I've recreated it. here's the simple way: Here is Pair.java =======8<========= public class Pair<F, S> { public Pair(F first, S second) { } } aspect IdempotentCache pertarget(cached()) { pointcut cached(): execution(public * *(..)) && within(Pair); } =======8<========= Compile it with 'ajc -1.5 Pair.java' Here is Test.java: =======8<========= public class Test { public static void main (String args[]) { Pair<String,String> pair = new Pair<String,String>("one","two"); } } =======8<========= > javac Test.java Test.java:3: cannot access Pair bad class file: .\Pair.class undeclared type variable: S Please remove or make sure it appears in the correct subdirectory of the classpath. Pair<String,String> pair = new Pair<String,String>("one","two"); ^ 1 error Or compiling with the JDT compiler: F:\workspaces\E32M5a\aspectjhead\tests\bugs152\pr126355\Test.java:1 [error] Inconsistent classfile encountered: The undefined type parameter S is referenced from within Pair<F,,S> public class Test { ^ 1 error
The generics signature creation logic was broken - and the introduction of the ajc$per interface (as a per clause was being used in the aspect) revealed the problem. The signature when the aspect isn't applying: <F:Ljava/lang/Object;S:Ljava/lang/Object;>Ljava/lang/Object;; The signature when the aspect is applying (rogue ',') <F:Ljava/lang/Object;,S:Ljava/lang/Object;>Ljava/lang/Object;; What the signature should be when the aspect is applying: <F:Ljava/lang/Object;S:Ljava/lang/Object;>Ljava/lang/Object;LIdempotentCache$ajcMightHaveAspect;; besides fixing the rogue comma, there is a lurking bug... related to adding interfaces to the myGen instance but retrieving them from the myType instance in LazyClassGen. It causes us to fail to add ajc$ generated interfaces types to the generated generic signature attribute. I've put in the first part of the fix which will sort out Jeff's situation, and added a commented out testcase to ajc152Tests for the secondary problem.
Fix for first problem available in latest dev build - still working on secondary problem.