Bug 366085 - cryptic Internal compiler error with "declare @type" and RetentionPolicy.SOURCE
Summary: cryptic Internal compiler error with "declare @type" and RetentionPolicy.SOURCE
Status: CLOSED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.12   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.9.19   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-08 13:38 EST by atao CLA
Modified: 2022-12-21 09:05 EST (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 atao CLA 2011-12-08 13:38:26 EST
Build Identifier: 20110916-0149

When an annotation with RetentionPolicy.SOURCE is used in a declare annotation such as 
   declare @type : (org.popsuite.domain2..*) : @PopBindable;

I get the  exception below.
As soon as I change it to RetentionPolicy.CLASS everything is fine. 
Was not easy to figure it out.

Eclipse Indigo 3.7.1
AspectJ : 1.6.12.20111003171000
AJDT: 2.2.0.e37x-20111004-0800


Internal compiler error
java.lang.ArrayIndexOutOfBoundsException: 1
    at org.aspectj.weaver.patterns.DeclareAnnotation.ensureAnnotationDiscovered(DeclareAnnotation.java:385)
    at org.aspectj.weaver.patterns.DeclareAnnotation.getAnnotation(DeclareAnnotation.java:359)
    at org.aspectj.weaver.bcel.BcelWeaver.applyDeclareAtType(BcelWeaver.java:1518)
    at org.aspectj.weaver.bcel.BcelWeaver.weaveParentTypeMungers(BcelWeaver.java:1483)
    at org.aspectj.weaver.bcel.BcelWeaver.weaveParentsFor(BcelWeaver.java:1325)
    at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1122)
    at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.weaveQueuedEntries(AjPipeliningCompilerAdapter.java:514)
    at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.queueForWeaving(AjPipeliningCompilerAdapter.java:447)
    at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterProcessing(AjPipeliningCompilerAdapter.java:432)
    at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$after$org_aspectj_ajdt_internal_compiler_CompilerAdapter$5$6b855184(CompilerAdapter.aj:98)
    at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:652)
    at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:392)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1024)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:268)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:181)
    at org.aspectj.ajde.core.internal.AjdeCoreBuildManager.performBuild(AjdeCoreBuildManager.java:105)
    at org.aspectj.ajde.core.AjCompiler.buildFresh(AjCompiler.java:100)
    at org.eclipse.ajdt.core.builder.AJBuilder.build(AJBuilder.java:255)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
    Barn.java   /_popAptProcessorTest2/src/org/popsuite/domain2 Unknown Java Problem


Reproducible: Always

Steps to Reproduce:
1. create an annotation (here @PopBindable) with RetentionPolicy.SOURCE
     
2. create an aspect with
        declare @type : (org.popsuite.domain2..*) : @PopBindable;

3. clean the project
Comment 1 Alexander Kriegisch CLA 2022-12-03 15:47:51 EST
This old problem still occurs in AspectJ 1.9.9.1, see
https://stackoverflow.com/q/74618269/1082681

In this case, the user tries to declare a Lombok @ToString annotation, see
https://projectlombok.org/api/lombok/ToString

Without having analysed the error, I am assuming it originates from the fact that the SOURCE retention causes the annotation to *not* be present during runtime - a special case which AJC or AJ weaver simply does not cover. Probably it would not be too difficult to put a safeguard into BcelWeaver.applyDeclareAtType or somewhere around there. For now, the weaver just throws this exception, which is annoying and should be fixed, but OTOH, it does not really make sense to paradoxically declare a source-level annotation on byte code.
Comment 2 Alexander Kriegisch CLA 2022-12-04 11:53:10 EST
I have created a preliminary bugfix PR (yet to be reviewed):
https://github.com/eclipse/org.aspectj/pull/196

There are no nice compiler warnings in it, but source-level annotation declarations are simply ignored (at least indirectly) by the weaver.
Comment 3 Alexander Kriegisch CLA 2022-12-04 11:55:26 EST
@Andy Clement: Would you please be so kind to create a target milestone 1.9.19 for this issue? I do not have the necessary rights, as it seems.
Comment 4 Andrew Clement CLA 2022-12-06 10:59:20 EST
1.9.19 now exists
Comment 5 Alexander Kriegisch CLA 2022-12-21 09:04:07 EST
PR with workaround merged, follow-up issue https://github.com/eclipse/org.aspectj/issues/201 created.
Comment 6 Alexander Kriegisch CLA 2022-12-21 09:05:42 EST
PR with workaround merged, follow-up issue https://github.com/eclipse/org.aspectj/issues/201 created.