Skip to content

querybean-generator:15.8.2 error: Failed to write EntityClassRegister #3582

@raphaelNguyen

Description

@raphaelNguyen

Hi @rbygrave, I would like to report an issue when using querybean-generator:15.8.2 in tandem with another annotation processor.

Summary

When used in tandem with specific other annotation processor (in this case manifold-exceptions), the querybean-generator:15.8.2 logs an error while trying to write embedded.example.EbeanEntityRegister due to an NPE from deep inside the JavacFiler logging code.

Note that I actually have other annotation processors (e.g. lombok, errorprone, etc...) but as I was building the simple reproducible project, I found that using querybean-generator:15.8.2 alongside these other processors does not cause this issue. I've only observe the issue with manifold-exceptions.

Details

Environment

java: 17.0.13
ebean: 15.8.2
maven: 3.9.9
manifold-exceptions: 2024.1.5

Reproduction steps:

Reproducible project https://github.com/integrated-application-development/querybean-generator-processor-issue. The README.md in this project also contains explanations of this issue. This project is a sample project containing a few entity beans and using querybean-generator and manifold-exceptions annotation processors.

  • Run mvn compile on the linked sample project.
  • Observe the following error message when the compile goal runs.
[INFO] --- compiler:3.13.0:compile (default-compile) @ query-bean-embedded-example ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 3 source files with javac [forked debug deprecation target 17] to target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error: Failed to write EntityClassRegister error:java.lang.NullPointerException: Cannot invoke "java.util.Queue.add(Object)" because "this.deferred" is null stack:[jdk.compiler/com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.report(Log.java:150), jdk.compiler/com.sun.tools.javac.util.Log.report(Log.java:660), jdk.compiler/com.sun.tools.javac.util.AbstractLog.warning(AbstractLog.java:163), jdk.compiler/com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:513), jdk.compiler/com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:435), io.ebean.querybean.generator.ProcessingContext.createWriter(ProcessingContext.java:399), io.ebean.querybean.generator.SimpleModuleInfoWriter.<init>(SimpleModuleInfoWriter.java:31), io.ebean.querybean.generator.Processor.writeModuleInfoBean(Processor.java:90), io.ebean.querybean.generator.Processor.process(Processor.java:53), jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1023), jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.runContributingProcs(JavacProcessingEnvironment.java:859), jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1265), jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1404), jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1234), jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:916), jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317), jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176), jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64), jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)]
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Without manifold-exceptions

At querybean-generator version 15.8.2 without manifold-exception added to the path processors, the querybeans generation logs the warning below but completes successfully. The compilation also completes successfully unless -Werror compilation flag is turned on.

[INFO] --- compiler:3.13.0:compile (default-compile) @ query-bean-embedded-example ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 3 source files with javac [forked debug deprecation target 17] to target\classes
[WARNING] File for type 'embedded.example.EbeanEntityRegister' created in the last round will not be subject to annotation processing.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Expected behaviour

compile does not throw any WARNING or ERROR related to querybean-generator.

Investigations

The stack trace suggests that this error happens when the underlying JavacFiler is trying to log the exact same [WARNING] observed above when running querybean-generator:15.8.2 without manifold-exceptions during JavacFiler.createSourceOrClassFile. When attempting this, the logging framework found that its DeferredDiagnosticHandler's deferred queue is null and threw an NPE which was captured and formatted into the [ERROR] seen above. A quick look at the code suggests that deferred queue is only set to null when DeferredDiagnosticHandler.reportDeferredDiagnostics is called to prevent accidental ongoing use.

This is likely linked to the changes made in #3542.

Part of the changes in this PR removes initModuleInfoBean() which creates SimpleModuleInfoWriter once if it's null and storing it in a instance field. Instead, it switches to creating a new SimpleModuleInfoWriter every time Processor.process is called. I had a sneaky feeling this might be what's causing the WARNING to be logged in the first place and did a quick test reverting this change (raphaelNguyen/ebean@fa8f98d). Using this locally installed version does not trigger the WARNING or ERROR mentioned above.

Thank you for your time.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions