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

Build fails when using picocli-codegen #1137

Closed
xligrd opened this issue Jul 28, 2020 · 13 comments
Closed

Build fails when using picocli-codegen #1137

xligrd opened this issue Jul 28, 2020 · 13 comments
Labels
theme: codegen An issue or change related to the picocli-codegen module type: bug 🐛
Milestone

Comments

@xligrd
Copy link

xligrd commented Jul 28, 2020

I set up picocli-codegen as an annotation processor and from that point on build always fails with:

error: FATAL ERROR: java.lang.ClassCastException: class com.sun.tools.javac.code.Attribute$Class cannot be cast to class javax.lang.model.type.TypeMirror (com.sun.tools.javac.code.Attribute$Class is in module jdk.compiler of loader 'app'; javax.lang.model.type.TypeMirror is in module java.compiler of loader 'platform')
at picocli.codegen.annotation.processing.CompletionCandidatesMetaData.extract(CompletionCandidatesMetaData.java:44)
at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor.buildOption(AbstractCommandSpecProcessor.java:499).

Where the related code looks like:

public static class LevelCompletion extends ArrayList<String> {
        public LevelCompletion() {
            super(Arrays.asList("OFF", "INFO", "WARN", ));
        }
    }

    @CommandLine.Option(names = "--level",
                        description = "Level.",
                        defaultValue = "OFF", 
                        showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
                        completionCandidates = LevelCompletion.class)
    private Level level;

Am I doing something wrong or is it bug?

@remkop
Copy link
Owner

remkop commented Jul 28, 2020

@xligrd Thank you for raising this.
I started investigating this.
Could you please provide some version information:

  • picocli version
  • java version
  • whether this error occurs when you are compiling in an IDE (which one?) or building with Maven/Gradle/some other build tool

Thanks!

@remkop remkop added the theme: codegen An issue or change related to the picocli-codegen module label Jul 28, 2020
@xligrd
Copy link
Author

xligrd commented Jul 28, 2020

Many thanks for quick reaction.
I tried multiple versions of picocli (4.1.4, 4.3.2 and 4.4.0), java version was 11.0.7 and It was built using Gradle.

@remkop
Copy link
Owner

remkop commented Jul 28, 2020

I would like to try to reproduce the problem.
Can you point me to a public repository or show me how to create a small project that reproduces the error?

@xligrd
Copy link
Author

xligrd commented Jul 28, 2020

Sure. I'm attaching a minimalistic application using which I was able to reproduce it.
picocli-test.zip

@remkop
Copy link
Owner

remkop commented Jul 28, 2020

@xligrd Please disregard my previous comment: I was able to reproduce the issue.
This seems to be a bug in the picocli-codegen annotation processor.

I am looking at how to fix this.

@remkop
Copy link
Owner

remkop commented Jul 28, 2020

@xligrd Thank you! 😅

@xligrd
Copy link
Author

xligrd commented Jul 28, 2020

Np :)

@remkop
Copy link
Owner

remkop commented Jul 28, 2020

I think I found the cause:

Index: picocli-codegen/src/main/java/picocli/codegen/annotation/processing/CompletionCandidatesMetaData.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- picocli-codegen/src/main/java/picocli/codegen/annotation/processing/CompletionCandidatesMetaData.java	(date 1595924589896)
+++ picocli-codegen/src/main/java/picocli/codegen/annotation/processing/CompletionCandidatesMetaData.java	(date 1595924589896)
@@ -41,7 +41,7 @@
                 for (ExecutableElement attribute : elementValues.keySet()) {
                     if ("completionCandidates".equals(attribute.getSimpleName().toString())) {
                         AnnotationValue typeMirror = elementValues.get(attribute);
-                        return new CompletionCandidatesMetaData((TypeMirror) typeMirror);
+                        return new CompletionCandidatesMetaData((TypeMirror) typeMirror.getValue());
                     }
                 }
             }

I will add some tests to verify this and try to roll out a bugfix release for this soon.
Thanks again for raising this!

@xligrd
Copy link
Author

xligrd commented Jul 28, 2020

Thanks a lot.

@remkop
Copy link
Owner

remkop commented Jul 29, 2020

I finally had time to create a test to confirm that this indeed fixes the issue.

Thanks again for raising this.
I will try to roll out a bugfix release soon (perhaps after fixing #1134).

@remkop remkop modified the milestones: 4.5, 4.4.1 Jul 29, 2020
@remkop
Copy link
Owner

remkop commented Aug 2, 2020

@xligrd Picocli 4.5 has been released, which includes this fix.

@agibsonccc
Copy link

agibsonccc commented Sep 26, 2021

I am still running in to this with picocli 4.6.1:
https://gist.github.com/agibsonccc/0e90c40e765e417d927de3c35ee6fabc

I am using graalvm jdk 11:
graalvm-ce-java11-21.2.0

@remkop do you want me to open a new issue?

@remkop
Copy link
Owner

remkop commented Sep 26, 2021

@agibsonccc Yes please create a new ticket. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: codegen An issue or change related to the picocli-codegen module type: bug 🐛
Projects
None yet
Development

No branches or pull requests

3 participants