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

IntelliJ IDEA fails to compile project w/ annotation processor #773

Closed
triceo opened this issue Jul 26, 2019 · 19 comments
Closed

IntelliJ IDEA fails to compile project w/ annotation processor #773

triceo opened this issue Jul 26, 2019 · 19 comments
Labels
theme: annotation-proc An issue or change related to the annotation processor

Comments

@triceo
Copy link
Contributor

triceo commented Jul 26, 2019

The IDE's compiler says:

Error:java: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor Unable to get public no-arg constructor

This can be worked around by disabling annotation processing in the IDE, but that setting then switches itself back on when the project's pom.xml is updated.

To reproduce, create a Maven project with maven-compiler-plugin configured with the Picocli annotation processor.

@remkop
Copy link
Owner

remkop commented Jul 26, 2019

Thanks for the report. I’ll take a look ASAP.

@remkop
Copy link
Owner

remkop commented Jul 26, 2019

What’s your Intelli/J version?

@triceo
Copy link
Contributor Author

triceo commented Jul 26, 2019

About my IDE.

@remkop
Copy link
Owner

remkop commented Jul 29, 2019

I was unable to reproduce the issue with my version of IntelliJ (2019.1.1). I will try to upgrade next.

Meanwhile, the picocli-examples module has 2 example Maven projects, and this is what I did to try to reproduce the issue:

  • check out the picocli project
  • in IntelliJ, do File > New > Project from Existing Sources...
  • specify the full path to picocli-examples/annotation-processing/example-maven-project-shading/pom.xml
  • click OK, and Next, Next, ... through the next wizard screens

This successfully generates the project, and I can see the annotation processor generating files during compilation in IntelliJ.

Can you try the above steps and let me know if you can reproduce the issue that way?

@remkop remkop added this to the 4.0.2 milestone Jul 29, 2019
@triceo
Copy link
Contributor Author

triceo commented Jul 30, 2019

Interesting. I wasn't able to reproduce using that approach.

Can you check out my project?
https://github.com/RoboZonky/robozonky

To get the compiler error, you shouldn't need to do anything else but
Build > Rebuild Project

@triceo
Copy link
Contributor Author

triceo commented Jul 30, 2019

(I should also note that I am seeing this issue ever since I upgraded to IntelliJ 2019.2. I was not seeing it on your 2019.1.)

@remkop
Copy link
Owner

remkop commented Jul 30, 2019

I am now trying to compile the robozonky project in IntelliJ 2019.1.1, but I am having trouble with the Java version. What is the required Java version for the project?

@triceo
Copy link
Contributor Author

triceo commented Jul 31, 2019

It requires Java 11 or later.

@remkop
Copy link
Owner

remkop commented Aug 1, 2019

Thanks, made some progress but now bumped into a different error:
Error:(64, 49) java: cannot find symbol
symbol: class NaturalLanguageStrategyParser
location: class com.github.robozonky.strategy.natural.SideEffectFreeParser

I will check again later.

@triceo
Copy link
Contributor Author

triceo commented Aug 2, 2019

Yeah, that's a problem I have not yet resolved. :-( Sorry for that.

If you mvn clean install -DskipTests from the command line in the robozonky-strategy-natural module, it will generate the parser and from that moment, IDEA project building will succeed.

@remkop
Copy link
Owner

remkop commented Aug 2, 2019

Cool, let me try that.

@remkop
Copy link
Owner

remkop commented Aug 6, 2019

I was able to successfully build the project in IntelliJ IDEA 2019.1.1. The problem does not manifest with that version.

After upgrading to IntelliJ IDEA 2019.2, I also see the error:

Error:java: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor Unable to get public no-arg constructor

Investigating....

remkop added a commit that referenced this issue Aug 6, 2019
…ructor to fix build error in IntelliJ IDEA 2019.2
@remkop
Copy link
Owner

remkop commented Aug 6, 2019

I added a public no-arg constructor to NativeImageConfigGeneratorProcessor, but it did not make a difference...

I tested by running gradlew -x check pubToMavenLocal in the picocli project, then change the robozonky project pom.xml to <version.info.picocli>4.0.2-SNAPSHOT</version.info.picocli>, re-import Maven config, I confirmed that IDEA picked up the changes (dependencies in project view show picocli 4.0.2-SNAPSHOT), rebuild the project... but got the same error. Will investigate further later.

remkop added a commit that referenced this issue Aug 9, 2019
remkop added a commit that referenced this issue Aug 9, 2019
@remkop remkop modified the milestones: 4.0.2, 4.0.3 Aug 12, 2019
@remkop
Copy link
Owner

remkop commented Aug 13, 2019

I added constructors to all annotation processors: the NativeImageConfigGeneratorProcessor constructor is public, its superclass constructors are protected.

I released picocli 4.0.2 with these changes. Can you verify with this version?

If the problem still exists there may be an issue in Intelli/J IDEA, or perhaps there’s another issue in picocli than the error message indicates. Either way we may need help from JetBrains.

@triceo
Copy link
Contributor Author

triceo commented Aug 13, 2019

Upgraded to 4.0.2, didn't help. :-(
Filed a bug with Jetbrains: https://youtrack.jetbrains.net/issue/IDEA-220545

@remkop remkop modified the milestones: 4.0.3, 4.0.4 Aug 28, 2019
@remkop remkop modified the milestones: 4.0.4, 4.0.5 Sep 8, 2019
@remkop remkop added the theme: annotation-proc An issue or change related to the annotation processor label Sep 19, 2019
@remkop remkop removed this from the 4.0.5 milestone Oct 10, 2019
@triceo
Copy link
Contributor Author

triceo commented Nov 2, 2019

It seems fixed in IntelliJ 2019.2.4.

@triceo triceo closed this as completed Nov 2, 2019
@remkop
Copy link
Owner

remkop commented Nov 2, 2019

That's great. They did not give much feedback on that ticket, but glad it's fixed!

@LeviPesin
Copy link

I get a similar error in IntelliJ 2022.3.3:

java: An exception has occurred in the compiler (17.0.6). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java: java.util.ServiceConfigurationError: javax.annotation.processing.Processor: picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor Unable to get public no-arg constructor
java: 	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:586)
java: 	at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:679)
java: 	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1240)
java: 	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
java: 	at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
java: 	at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
java: 	at org.jetbrains.jps.javac.Iterators$10.hasNext(Iterators.java:207)
java: 	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:886)
java: 	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
java: 	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
java: 	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
java: 	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
java: 	at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:237)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.lambda$compileJava$2(JavaBuilder.java:524)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.invokeJavac(JavaBuilder.java:587)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:522)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:366)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:291)
java: 	at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:245)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1523)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1153)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1303)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1118)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:889)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:471)
java: 	at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:197)
java: 	at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:150)
java: 	at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:371)
java: 	at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:193)
java: 	at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:211)
java: 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java: 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java: 	at java.base/java.lang.Thread.run(Thread.java:833)
java: Caused by: java.lang.NoClassDefFoundError: picocli/CommandLine$Model$IAnnotatedElement
java: 	at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
java: 	at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3373)
java: 	at java.base/java.lang.Class.getConstructor0(Class.java:3578)
java: 	at java.base/java.lang.Class.getConstructor(Class.java:2271)
java: 	at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:666)
java: 	at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:663)
java: 	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
java: 	at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:674)
java: 	... 31 more
java: Caused by: java.lang.ClassNotFoundException: picocli.CommandLine$Model$IAnnotatedElement
java: 	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
java: 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
java: 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
java: 	... 39 more
java: Compilation failed: internal java compiler error

What should I do to fix it?

@remkop
Copy link
Owner

remkop commented Apr 13, 2023

Hi @LeviPesin, the previous time this happened it turned out to be a problem in Intelli/J.
I don't think there is anything that can be done in picocli to work around it.
You may be able to work around it by changing project settings (based on earlier comments in this ticket).

I believe the best course of action is to file a ticket with JetBrains.
You may want to reference the previous ticket (https://youtrack.jetbrains.net/issue/IDEA-220545) as related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: annotation-proc An issue or change related to the annotation processor
Projects
None yet
Development

No branches or pull requests

3 participants