eclipse-aspectj / aspectj

Other
303 stars 86 forks source link

Misleading/No error during compile after annotation processing with faulty aj aspect file #240

Closed warrenc5 closed 1 year ago

warrenc5 commented 1 year ago

version aspectj 1.9.19 reproducible test case supplied https://github.com/warrenc5/aspectj-bug.git

when I have aspectj maven plugin generate aj files from an annotation processor in that project and there is an error in the aspect file then I get a stacktrace and abort

[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.14.0:test-compile (test-compile) on project aspectj-bug: AJC compiler errors:
[ERROR] abort ABORT -- (NullPointerException) null
[ERROR] null
[ERROR] java.lang.NullPointerException
[ERROR]     at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.hasAspectDeclarations(AjLookupEnvironment.java:1475)
[ERROR]     at org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment.buildTypeBindings(AjLookupEnvironment.java:1468)
[ERROR]     at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:870)
[ERROR]     at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.processAnnotationsInternal(Compiler.java:1021)
[ERROR]     at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:947)
[ERROR]     at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:451)
[ERROR]     at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:427)
[ERROR]     at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1096)
[ERROR]     at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:275)
[ERROR]     at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:188)
[ERROR]     at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:103)
[ERROR]     at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:47)
[ERROR]     at org.aspectj.tools.ajc.Main.run(Main.java:372)
[ERROR]     at org.aspectj.tools.ajc.Main.runMain(Main.java:250)

expected to get an informative error message same as when I run with the .aj file in the src/test/aspect directory.

[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.14.0:test-compile (test-compile) on project aspectj-bug: AJC compiler errors:
[ERROR] error at BROKEN HERE
[ERROR]        ^^^
[ERROR] /home/wozza/code/aspectj-bug/src/test/aspect/MyTestAspect.aj:26:0::0 Syntax error, insert ";" to complete aspect member declaration
[ERROR]

Please assist.

kriegaex commented 1 year ago

Thanks for the report. The reproducible test case was essential for me to quickly identify the problem. Keep up the good practice!

I do not have much time, but I think that I fixed the problem. At least, when using the latest AspectJ snapshot, the result looks as expected:

[INFO] --- aspectj-maven-plugin:1.13.1:test-compile (test-compile) @ aspectj-bug ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
my.MyAnnotationProcessor processing 
options: []
root elements :[MyVictim, MyTest]
root elements :[]
creating resource file:AJ_GH-240/target/generated-test-sources/aspectj-maven-plugin/MyTestAspect.aj
[ERROR] Syntax error, insert ";" to complete aspect member declaration
    AJ_GH-240\target\generated-test-sources\aspectj-maven-plugin\MyTestAspect.aj:26
BROKEN HERE
       ^^^^

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

See also the PR I created for you: https://github.com/warrenc5/aspectj-bug/pull/2.

kriegaex commented 1 year ago

Probably you know already, but your workaround until the next release would be to use Maven Compiler with <proc>only</proc> in combination with AspectJ Maven with <proc>none</proc>, letting Javac do the annotation processing instead of Ajc.

warrenc5 commented 1 year ago

Thank you, I will. Thanks again.