Bug 126355 - Upgrading Aspectj to 1.5: After compiling project with ajc release 1.5, compiling jsps with imports containg generics causes errors, Worked under aspectj 1.2.1
Summary: Upgrading Aspectj to 1.5: After compiling project with ajc release 1.5, compi...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-03 10:46 EST by jeff CLA
Modified: 2006-05-23 10:06 EDT (History)
0 users

See Also:


Attachments
the attachment is a tar archived file containing a test case ot reproduce the bug (10.00 KB, application/octet-stream)
2006-02-03 10:53 EST, jeff CLA
no flags Details
IdempotentCache related source files (10.00 KB, application/x-tar)
2006-05-22 18:30 EDT, jeff CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description jeff CLA 2006-02-03 10:46:55 EST
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.
Comment 1 jeff CLA 2006-02-03 10:53:31 EST
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
Comment 2 jeff CLA 2006-02-03 11:31:05 EST
note:
compiled the project using iajc ant task
Comment 3 Andrew Clement CLA 2006-02-10 09:54:29 EST
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
Comment 4 jeff CLA 2006-02-10 11:17:14 EST
(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 
Comment 5 Andrew Clement CLA 2006-05-22 06:47:12 EDT
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 ?
Comment 6 jeff CLA 2006-05-22 18:30:23 EDT
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
Comment 7 Andrew Clement CLA 2006-05-23 04:09:28 EDT
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
Comment 8 Andrew Clement CLA 2006-05-23 06:34:42 EDT
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.
Comment 9 Andrew Clement CLA 2006-05-23 10:06:59 EDT
Fix for first problem available in latest dev build - still working on secondary problem.