-
Notifications
You must be signed in to change notification settings - Fork 58
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
MissingOverrideAnnotation: NPE in classDecl.getBody().getMarkers() with Kotlin files #234
Comments
Yes, what you have identified here is indeed problematic. I've made the code more robust there, by not passing in a The |
@vlsi Thanks for reporting! |
Note: We try to explicitly declare all parameters as non- @With(onParam_ = @NonNull)
@Getter
Block body; |
Yes, that would definitely make sense. I will look into it. |
That is strange. I guess you have For reference, the decompiled code is @NonNull
public @NonNull ClassDeclaration withBody(final Block body) {
return this.body == body ? this : new ClassDeclaration(this.padding, this.annotations, this.id, this.prefix, this.markers, this.leadingAnnotations, this.modifiers, this.kind, this.name, this.typeParameters, this.primaryConstructor, this.extendings, this.implementings, this.permitting, body, this.type);
} Kotlin already rejects lateinit var cu: J.ClassDeclaration
cu.withBody(null) // Null can not be a value of a non-null type J.Block So if you miss |
Interesting. I would have to look at the byte code. But if I declare the |
I can at least confirm that in my IDEA (2023.3.2) it behaves this way. For Java calls our |
Please note that these are calls to |
I found this IDEA bug: https://youtrack.jetbrains.com/issue/IDEA-278199/IntelliJ-does-not-apply-NonnullByDefault-to-bytecode. I still don't understand why Java and Kotlin behave differently here. |
Technically speaking, |
Yes, JSpecify looks nice and has gained quite some traction. While I doubt it would mak much difference here, it could indeed be worth investigating as an alternative. Thanks for bringing this up. |
How are you running OpenRewrite?
See apache/jmeter#6217,
./gradlew :src:jorphan:rewriteRun
What is the smallest, simplest way to reproduce the problem?
No idea
What did you expect to see?
MissingOverrideAnnotation
should either skip Kotlin files or it should addoverride
respectively.What did you see instead?
The issue might be caused by
withBody(null)
(see https://github.com/openrewrite/rewrite/blob/fb7dbd6c95ef5492301dcb941e7f8eefd223621e/rewrite-java/src/main/java/org/openrewrite/java/internal/template/AnnotationTemplateGenerator.java#L226 ), however, I'm not sure what triggers it.The problematic class is https://github.com/apache/jmeter/blob/09c3f810dda7efaf1510ac062454d978d90a0741/src/jorphan/src/main/kotlin/org/apache/jorphan/gui/CardLayoutWithSizeOfCurrentVisibleElement.kt#L31
The text was updated successfully, but these errors were encountered: