Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"warning: Can't force a new processing round. Lombok won't work." with Bazel #1290

Closed
venantius opened this issue Feb 7, 2017 · 25 comments
Closed

Comments

@venantius
Copy link

I've been running into this issue when building a project with Bazel that uses Lombok for its annotations:

INFO: From Building projects/omnes/omnes-clients/libomnes-clients.jar (79 source files):
warning: Can't force a new processing round. Lombok won't work.Target //projects/omnes/omnes-clients:omnes-clients up-to-date:
  bazel-bin/projects/omnes/omnes-clients/libomnes-clients.jar
INFO: Elapsed time: 6.225s, Critical Path: 3.03s

I'm not totally clear what the new processing round error refers to - I had a look at the source code and it looks like it tries to create a temporary file somewhere and fails when that file creation fails. Is that more or less correct?

@rspilker
Copy link
Collaborator

rspilker commented Feb 9, 2017

That is correct. Lombok needs multiple processor rounds to do its job. That is uncommon for annotation processors and no API exists for this. But if a new source file is generated, a new round will be triggered.

Can you also find the stacktrace that's printed to the error stderr?

@venantius
Copy link
Author

I've opened a ticket with the Bazel folks to try and figure out where the stacktrace is going - it's buried in the logs somewhere and I'm not sure where. Do you know if the trace would be dumped to stdout or stderr?

@cushon
Copy link
Contributor

cushon commented Feb 13, 2017

I repro'd the error with Bazel, and the log includes:

error: Lombok annotation handler class lombok.javac.handlers.HandleData failed ... java.lang.NoSuchFieldError: members_field

The type of that field changed in JDK 9: http://hg.openjdk.java.net/jdk9/dev/langtools/annotate/85ff2daae534/src/share/classes/com/sun/tools/javac/code/Symbol.java#l913

It logged two stack traces:

java.lang.NoSuchFieldError: members_field
	at lombok.javac.handlers.JavacHandlerUtil.fixMethodMirror(JavacHandlerUtil.java:962)
	at lombok.javac.handlers.JavacHandlerUtil.injectMethod(JavacHandlerUtil.java:953)
	at lombok.javac.handlers.HandleConstructor.generateConstructor(HandleConstructor.java:242)
	at lombok.javac.handlers.HandleConstructor.generateRequiredArgsConstructor(HandleConstructor.java:191)
	at lombok.javac.handlers.HandleData.handle(HandleData.java:58)
	at lombok.javac.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.java:109)
	at lombok.javac.HandlerLibrary.handleAnnotation(HandlerLibrary.java:244)
	at lombok.javac.JavacTransformer$AnnotationVisitor.visitAnnotationOnType(JavacTransformer.java:87)
	at lombok.javac.JavacNode.traverse(JavacNode.java:120)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:143)
	at lombok.javac.JavacNode.traverse(JavacNode.java:83)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:143)
	at lombok.javac.JavacNode.traverse(JavacNode.java:78)
	at lombok.javac.JavacAST.traverse(JavacAST.java:139)
	at lombok.javac.JavacTransformer.transform(JavacTransformer.java:71)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:294)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:74)
java.lang.NullPointerException
	at lombok.javac.apt.LombokFileObjects.createEmpty(LombokFileObjects.java:109)
	at lombok.javac.apt.InterceptingJavaFileManager.getJavaFileForOutput(InterceptingJavaFileManager.java:47)
	at com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:414)
	at com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:388)
	at lombok.javac.apt.LombokProcessor.forceNewRound(LombokProcessor.java:333)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:322)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:74)

@rspilker
Copy link
Collaborator

I think I've fixed the NPE, and can reproduce the members_field problem.

@rspilker
Copy link
Collaborator

Also just fixed the members_field problem.

@rspilker
Copy link
Collaborator

Can you test against an edge release?

@venantius
Copy link
Author

Let me take a look right now.

@venantius
Copy link
Author

I only get the one stacktrace (with both the edge release and the other version we were using, which was 1.16.8). At least, one stacktrace per library Lombok tries to build, which given the size of our monorepo, is a lot...but at least the stacktrace is always the same:

warning: Can't force a new processing round. Lombok won't work.INFO: From Building common/utils/libutils.jar (53 source files):
java.lang.NullPointerException
	at lombok.javac.apt.LombokFileObjects.createEmpty(LombokFileObjects.java:123)
	at lombok.javac.apt.InterceptingJavaFileManager.getJavaFileForOutput(InterceptingJavaFileManager.java:47)
	at com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:414)
	at com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:388)
	at lombok.javac.apt.LombokProcessor.forceNewRound(LombokProcessor.java:333)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:322)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:74)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:826)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:742)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2000(JavacProcessingEnvironment.java:100)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1046)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1153)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1120)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:814)
	at com.sun.tools.javac.api.JavacTaskImpl$1.call(JavacTaskImpl.java:97)
	at com.sun.tools.javac.api.JavacTaskImpl$1.call(JavacTaskImpl.java:93)
	at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:128)
	at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:93)
	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:87)
	at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:104)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder$1.invokeJavac(SimpleJavaLibraryBuilder.java:163)
	at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:59)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:166)
	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:178)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.processRequest(BazelJavaBuilder.java:90)
	at com.google.devtools.build.buildjar.BazelJavaBuilder.main(BazelJavaBuilder.java:50)```

@rspilker
Copy link
Collaborator

Are you sure the edge release is being used by all those projects? Can you explain how I can test this using Bazel myself?

@venantius
Copy link
Author

venantius commented Feb 14, 2017

I am reasonably sure the edge release is being used by all of those projects. Each project has a list of deps that are specified like so:

java_library(
    name = "spinaltap-client",
    deps = [
       ...
        "//third_party/plugins:org.projectlombok_lombok",
       ...
    ],
    srcs = glob(["src/main/java/**/*.java"]),
)

In //third_party/plugins, we have the following:

java_library(
    name = "org.projectlombok_lombok",
    exports = ["//third_party:org.projectlombok_lombok"],
    exported_plugins = [":lombok_plugin"],
)

java_plugin(
    name = "lombok_plugin",
    processor_class = "lombok.launch.AnnotationProcessorHider$AnnotationProcessor",
    deps = ["//third_party:org.projectlombok_lombok"],
)

This, in turn, points to //third_party:org.projectlombok_lombok, which looks like the following:

java_import(
    name = "org.projectlombok_lombok",
    jars = [
        "jars/lombok-edge.jar"
        # "jars/org.projectlombok/lombok/1.16.8/2ce9de13f277ec1600e7e04231477e3e5f59d317/lombok-1.16.8.jar"
    ],
)

This would be built using a command like bazel build //projects/spinaltap/spinaltap-client/... --strategy=Javac=local

So there isn't really an opportunity for another version of Lombok to sneak in anywhere.

It's possible I've managed to screw something up somewhere, so it'd be nice if @cushon could confirm my findings.

@cushon
Copy link
Contributor

cushon commented Feb 14, 2017

I'm also still seeing the NPE, here's a simpler repro:

Install Bazel: https://bazel.build/versions/master/docs/install.html

and then:

wget https://github.com/rzwitserloot/lombok/files/772824/repro.zip
unzip repro.zip
wget https://projectlombok.org/lombok-edge.jar
bazel clean; bazel build --strategy=Javac=local :test
java.lang.NullPointerException
	at lombok.javac.apt.LombokFileObjects.createEmpty(LombokFileObjects.java:123)
	at lombok.javac.apt.InterceptingJavaFileManager.getJavaFileForOutput(InterceptingJavaFileManager.java:47)
	at com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:414)
	at com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:388)
	at lombok.javac.apt.LombokProcessor.forceNewRound(LombokProcessor.java:333)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:322)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:74)

@venantius
Copy link
Author

I'm also noticing that the line numbers on my and @cushon's stacktraces line up -- our edge jar stacktrace comes from line 123, and the 1.16.8 stacktrace goes to line 109

@venantius
Copy link
Author

Any news on this, @rspilker?

@rspilker
Copy link
Collaborator

Yeah. the latest edge release added some extra prints to pinpoint the problem. I'll see if I can link the other issue

@rspilker
Copy link
Collaborator

See #985 for progress on jdk9 support.

@rspilker
Copy link
Collaborator

The newest edge release might give us more insight. Can someone please try it out? See #985 (comment)

@cushon
Copy link
Contributor

cushon commented Jun 12, 2017

The default Bazel config uses a filemanager that breaks Lombok's assumptions:

Test.java:4: warning: lombok.javac.apt.LombokProcessor could not be initialized. Lombok will not run during this compilation: java.lang.IllegalArgumentException: com.google.devtools.build.buildjar.javac.BlazeJavacMain$ClassloaderMaskingFileManager extends com.sun.tools.javac.file.JavacFileManager
public class Test {
       ^
  	at lombok.javac.apt.LombokFileObjects.getCompiler(LombokFileObjects.java:129)
  	at lombok.javac.apt.InterceptingJavaFileManager.<init>(InterceptingJavaFileManager.java:40)
  	at lombok.javac.apt.LombokProcessor.placePostCompileAndDontMakeForceRoundDummiesHook(LombokProcessor.java:164)
  	at lombok.javac.apt.LombokProcessor.init(LombokProcessor.java:85)
  	at lombok.core.AnnotationProcessor$JavacDescriptor.want(AnnotationProcessor.java:87)
  	at lombok.core.AnnotationProcessor.init(AnnotationProcessor.java:140)
  	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.init(AnnotationProcessor.java:69)
  	at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:675)
  	at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:774)
  	at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:869)
  	at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2200(JavacProcessingEnvironment.java:108)
  	at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1204)
  	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1313)
  	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1267)
  	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:943)
  	at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100)
  	at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142)
  	at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96)
  	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90)
  	at com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:103)
  	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder$1.invokeJavac(SimpleJavaLibraryBuilder.java:166)
  	at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:52)
  	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:169)
  	at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:181)
  	at com.google.devtools.build.buildjar.BazelJavaBuilder.processRequest(BazelJavaBuilder.java:89)
  	at com.google.devtools.build.buildjar.BazelJavaBuilder.main(BazelJavaBuilder.java:49)
Test.java:5: error: variable x not initialized in the default constructor
  public final int x;
                   ^
Target //:test failed to build

Disabling that part of Bazel causes Lombok to fail this way instead:

java.lang.IllegalArgumentException: Problems in URI 'file://lombok/dummy/ForceNewRound0.java' (lombok/dummy/ForceNewRound0.java)
	at lombok.javac.apt.LombokFileObjects$Java9Compiler.wrap(LombokFileObjects.java:156)
	at lombok.javac.apt.LombokFileObjects.createEmpty(LombokFileObjects.java:133)
	at lombok.javac.apt.InterceptingJavaFileManager.getJavaFileForOutput(InterceptingJavaFileManager.java:47)
	at com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:478)
	at com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:417)
	at lombok.javac.apt.LombokProcessor.forceNewRound(LombokProcessor.java:333)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:322)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:74)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:968)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:884)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2200(JavacProcessingEnvironment.java:108)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1204)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1313)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1267)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:943)
	at com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100)
	at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142)
	at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96)
	at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90)
	at com.google.devtools.build.buildjar.VanillaJavaBuilder.run(VanillaJavaBuilder.java:174)
	at com.google.devtools.build.buildjar.VanillaJavaBuilder.main(VanillaJavaBuilder.java:94)
Caused by: java.lang.IllegalArgumentException: URI has an authority component
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:53)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at lombok.javac.apt.LombokFileObjects$Java9Compiler.wrap(LombokFileObjects.java:154)
	... 22 more
warning: Can't force a new processing round. Lombok won't work.

@rspilker
Copy link
Collaborator

A new edge release might contain the fix. Feedback is welcome.

@cushon
Copy link
Contributor

cushon commented Jun 13, 2017

That fixed the IllegalArgumentException: Problems in URI ... error. The other failure is still there. (If you want to try it, I'm using the repro I posted up above).

Test.java:4: warning: lombok.javac.apt.LombokProcessor could not be initialized. Lombok will not run during this compilation: java.lang.IllegalArgumentException: com.google.devtools.build.buildjar.javac.BlazeJavacMain$ClassloaderMaskingFileManager extends com.sun.tools.javac.file.JavacFileManager
public class Test {
       ^
        at lombok.javac.apt.LombokFileObjects.getCompiler(LombokFileObjects.java:129)
        at lombok.javac.apt.InterceptingJavaFileManager.<init>(InterceptingJavaFileManager.java:40)
        at lombok.javac.apt.LombokProcessor.placePostCompileAndDontMakeForceRoundDummiesHook(LombokProcessor.java:164)
        at lombok.javac.apt.LombokProcessor.init(LombokProcessor.java:85)
        at lombok.core.AnnotationProcessor$JavacDescriptor.want(AnnotationProcessor.java:87)
        at lombok.core.AnnotationProcessor.init(AnnotationProcessor.java:140)
        at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.init(AnnotationProcessor.java:69)

@rspilker
Copy link
Collaborator

A new edge release (2017-06-19 22:15:39 UTC) might contain the fix. Feedback is welcome.

@cushon
Copy link
Contributor

cushon commented Jun 19, 2017

The repro no longer crashes. (I haven't done anything to verify the output is correct.)

@rspilker
Copy link
Collaborator

rspilker commented Jul 3, 2017

Will be part of 1.16.18, scheduled to be released very soon.

@rspilker rspilker closed this as completed Jul 3, 2017
@sergeykad
Copy link

sergeykad commented Mar 25, 2018

I started getting the NPE after switching to Java 9.
I am using Lombok 1.16.20.
The error is the same as in the #1290 (comment).

java.lang.NullPointerException
        at lombok.javac.apt.LombokFileObjects.createEmpty(LombokFileObjects.java:123)
        at lombok.javac.apt.InterceptingJavaFileManager.getJavaFileForOutput(InterceptingJavaFileManager.java:47)
        at jdk.compiler/com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:499)
        at jdk.compiler/com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:425)
        at lombok.javac.apt.LombokProcessor.forceNewRound(LombokProcessor.java:333)
        at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:322)
        at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:114)
        at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:164)
        at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:74)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:968)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:884)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2200(JavacProcessingEnvironment.java:108)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1206)
        at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1315)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1246)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:922)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:100)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:142)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:96)
        at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:90)

@fswijmans
Copy link

While following the code of @venantius above, the bazel build works, but it fails on bazel test. It can't find the Getter/Setter methods.

Can anyone help me how to instruct bazel to apply the plugin to a test target?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants