eclipse-aspectj / aspectj

Other
303 stars 86 forks source link

APT problem: StackOverflowError in RoundDispatcher.handleProcessor #195

Open kriegaex opened 1 year ago

kriegaex commented 1 year ago

This issue came up in https://github.com/dev-aspectj/aspectj-maven-plugin/issues/108, but it is not a problem concerning the Maven plugin. Instead, it seems to be related to annotation processing (APT) support for AJC:

There is an annotation processor on the classpath, namely com.querydsl:querydsl-apt:5.0.0-jakarta. It contains a file META-INF/services/javax.annotation.processing.Processor with the following content:

com.querydsl.apt.jpa.JPAAnnotationProcessor

That annotation processor handles the @jakarta.persistence.MappedSuperclass annotations found on two classes in the sample repository.

While Javac (used by Maven Compiler Plugin) can correctly generate code, it seems as if the annotation processor throws off AJC like this (error message with additional line breaks):

...\baz\src\main\java\com\foobar\showme\baz\TimestampedJPADurable.java [error]
Internal compiler error: java.lang.Exception:
java.lang.StackOverflowError at 
  org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:172)
(no source information available)

A reproducer is at https://github.com/zenbones/showme. Thanks to @zenbones for reporting the problem.

See also https://github.com/dev-aspectj/aspectj-maven-plugin/issues/108#issuecomment-1328225704 for an AspectJ Maven workaround which can also be applied to the AJC command line: letting Javac take care of annotation processing and then using -proc:none for AJC.

kriegaex commented 1 year ago

I debugged into AJC, because unfortunately the upstream Eclipse Jave Compiler (ACJ) underneath AJC does not log a full stack trace for the stack overflow error. Here it is:

java.lang.StackOverflowError
    at com.querydsl.apt.ExtendedTypeFactory$2.visitBase(ExtendedTypeFactory.java:207)
    at com.querydsl.apt.ExtendedTypeFactory$2.visitTypeVariable(ExtendedTypeFactory.java:252)
    at com.querydsl.apt.ExtendedTypeFactory$2.visitTypeVariable(ExtendedTypeFactory.java:201)
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.model.TypeVariableImpl.accept(TypeVariableImpl.java:77)
    at java.compiler@19.0.1/javax.lang.model.util.AbstractTypeVisitor6.visit(AbstractTypeVisitor6.java:91)
    at com.querydsl.apt.ExtendedTypeFactory$2.visitTypeVariable(ExtendedTypeFactory.java:254)
    at com.querydsl.apt.ExtendedTypeFactory$2.visitTypeVariable(ExtendedTypeFactory.java:201)
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.model.TypeVariableImpl.accept(TypeVariableImpl.java:77)
    at java.compiler@19.0.1/javax.lang.model.util.AbstractTypeVisitor6.visit(AbstractTypeVisitor6.java:91)
    at com.querydsl.apt.ExtendedTypeFactory$2.visitTypeVariable(ExtendedTypeFactory.java:254)
    at com.querydsl.apt.ExtendedTypeFactory$2.visitTypeVariable(ExtendedTypeFactory.java:201)
       (and many more repetitions of the last 4 lines)

It would be interesting to see if that works in plain vanilla ECJ or is AJC-specific. I will try that next after work.

kriegaex commented 1 year ago

Update (CC @zenbones): I quickly checked during a break, and it definitely is not an AJC problem. The same occurs when compiling the project with plain vanilla ECJ 3.31.0. And also there -proc:none makes the project compile, but of course in that case no code generation via APT takes place.

Update: Bug ticket https://github.com/eclipse-jdt/eclipse.jdt.core/issues/565 created.