Bug 389750 - Inconsistent classfile encountered: The undefined type parameter xxx is referenced from within yyy
Summary: Inconsistent classfile encountered: The undefined type parameter xxx is refer...
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.7.1   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: 1.7.2   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-17 14:25 EDT by Matthew Adams CLA
Modified: 2012-09-20 12:25 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Adams CLA 2012-09-17 14:25:23 EDT
With the declare parents pattern below, I'm getting this **runtime** error (compiler completes ok):

Inconsistent classfile encountered: The undefined type parameter ID is referenced from within PersistableAspect

If I remove the generics part of the interface declaration, the error goes away.  Here's the pattern:

interface:
==========
package example.trait;

// imports...

public interface Persistable<ID extends Serializable> {

	Object getOid();

	ID getId();

	String getIdString();

	long getVersion();
}

annotation:
===========
package example.anno;

// imports...

@Target(TYPE)
@Retention(RUNTIME)
@Trait
public @interface Persistable {

	String in() default "MONGO";

	StoreType inAsEnum() default StoreType.MONGO;

	String id() default "STRING";

	IdType idAsEnum() default IdType.STRING;
}


aspect:
=======
package example.aspect;

// imports...

public privileged aspect PersistableAspect {

	public interface I<ID extends Serializable> extends example.trait.Persistable<ID> {
	}

	public interface L extends I<Long> {
	}

	public interface S extends I<String> {
	}

	declare parents :
        (@Persistable(id="LONG") *)
        implements L;

	declare parents :
        (@Persistable(id="STRING") *)
        implements S;

	// remaining code is ITDs introducing vars & methods...
}
Comment 1 Andrew Clement CLA 2012-09-18 16:03:19 EDT
by the 'app/app-test' I mean I get these errors:

[ERROR] Failed to execute goal on project foundation-domain: Could not resolve dependencies for project com.scispike:foundation-domain:jar:0.1.0.BUILD-SNAPSHOT: The following artifacts could not be resolved: org.example:app-support:jar:0.1.0.BUILD-SNAPSHOT, org.example:app-test-support:jar:0.1.0.BUILD-SNAPSHOT: Failure to find org.example:app-support:jar:0.1.0.BUILD-SNAPSHOT in http://maven.springframework.org/release was cached in the local repository, resolution will not be reattempted until the update interval of maven.springframework.org has elapsed or updates are forced -> [Help 1]

Until I remove the lines:

        <dependency>
            <groupId>org.example</groupId>
            <artifactId>app-support</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>app-test-support</artifactId>
            <version>${project.parent.version}</version>
            <scope>test</scope>
        </dependency>

With those gone, and using the commit you referenced and running mvn clean verify, I now see the error, hurray!
Comment 2 Andrew Clement CLA 2012-09-18 16:27:53 EDT
For some reason I was under the impression this was a new problem in 1.7.1 that didn't happen with 1.7.0 - but I've tried 1.7.1/1.7.0/1.6.12 and they all have the same problem.
Comment 3 Matthew Adams CLA 2012-09-18 16:43:46 EDT
I'm glad you can repro.

Ah, I know now why those dependencies are there that you had to remove.  That's a copy/paste bug, which I've fixed & committed in the head.  Sorry 'bout that!

If you want me to fix it back at the commit that contains the error, then I'll have to do that, too.  Let me know if that's something you want me to do.
Comment 4 Andrew Clement CLA 2012-09-18 16:53:54 EDT
From debugging Matthews code, distilled the entire problem to this:

Code.aj====
import java.io.*;

interface Persistable<ID extends Serializable> {

}

public aspect Code {

  public interface I<ID extends Serializable> extends Persistable<ID> {
  }

  public static void foo() {}

  public boolean I.equals(Persistable<?> that) {
    return false;
  }
}
===

Clazz.java===
public class Clazz {
  public static void main(String[] argv) {
    Code.foo();
  }
}
===

ajc -1.5 Code.aj
ajc -1.5 Clazz.java

org.aspectj.org.eclipse.jdt.internal.compiler.problem.AbortCompilation: Pb(538) Inconsistent classfile encountered: The undefined type parameter ID is referenced from within Code
Comment 5 Matthew Adams CLA 2012-09-18 17:34:16 EDT
FYI, not that you need it now that you've distilled the problem, but I created a new branch called "aspectj-bug-389750" as a branch of commit 368b7dc827ef0237bdb6d460320cf1e7fbedf7da (the one containing the aj error) and fixed the poms there.
Comment 6 Andrew Clement CLA 2012-09-19 13:32:05 EDT
fix committed. The problem is due to missing type variables in the generic signature for the ITD helper methods that get generated.  They are missing because they are declared on the target type and we need to copy them over to the ITD. I confirmed this fixes it for your failing scenario that I could previously recreate.
Comment 7 Matthew Adams CLA 2012-09-19 13:39:59 EDT
Great, Andy!  In which release do you expect this to be included?
Comment 8 Andrew Clement CLA 2012-09-19 19:43:17 EDT
it'll be in 1.7.2. I'll put a 1.7.2 snapshot on the spring maven repo.  It'll be in AJDT shortly too.
Comment 9 Matthew Adams CLA 2012-09-20 12:25:25 EDT
I grabbed 1.7.2.BUILD-SNAPSHOT & everything tested ok.