Bug 571104 - Compiler error when not explicitly declaring an aspect nested in an interface as static
Summary: Compiler error when not explicitly declaring an aspect nested in an interface...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.9.5   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-10 20:42 EST by Alexander Kriegisch CLA
Modified: 2021-06-16 01:13 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kriegisch CLA 2021-02-10 20:42:24 EST
See https://stackoverflow.com/a/42607016/1082681.

Trying to compile this

public interface MyInterface {
  void one();
  void two();

  aspect MarkerAnnotationInheritor {
    // Implementing classes should inherit marker annotation
    declare @type: MyInterface+ : @Marker;
    // Overriding methods 'two' should inherit marker annotation
    declare @method : void MyInterface+.two() : @Marker;
  }
}

yields the following compiler error:

java.lang.NullPointerException
at org.aspectj.weaver.patterns.DeclareAnnotation.getAnnotationType(DeclareAnnotation.java:433)
at org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder.visit(AsmHierarchyBuilder.java:554)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:378)
at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1637)
at  ... oBuildJob.run(AutoBuildJob.java:244)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Compile error: NullPointerException thrown: null

An class (or aspect, for that matter) nested inside an interface should be implicitly static, even if not declared as such explicitly. Here however, I have to explicitly declare the nested aspect as static.
Comment 1 Alexander Kriegisch CLA 2021-02-10 20:59:50 EST
I forgot to mention that if I declare a nested class inside the interface, there is no need to explicitly use 'static', the compiler only dies when I omit the keyword for a nested aspect.

On a side note, I created this issue on Bugzilla, just because the AJDT error dialog suggested me to and because Bugzilla for AspectJ still permits to create new issues. I think like this we will have new issues both here and on GitHub forever. If you do not mind, then so be it. ;-)
Comment 2 Andrew Clement CLA 2021-06-16 01:13:09 EDT
This ought to be a reasonable issue to dig into (if you want to?) if the problem is that we simply aren't implicitly setting the static bit for an aspect inside an interface where there is code setting it implicitly for a class.

I might start looking around TheOriginalJDTParserClass.consumeCLassOrRecordHeaderName1 to see if the point where we build the type declaration we are taking something like that into account (am I inside an interface). And then are we missing that when consuming an aspect header name.

If not there I'd be setting a breakpoint on the SourceTypeBinding and seeing when the modifiers get the static bit set (this is all assuming a test case that is doing it for a class inside an interface).  Then wherever that is being done, mirror that behaviour in the aspect codepath.