question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`null` value in annotation arguments if annotation originates from Java and argument is Kotlin's `const val`

See original GitHub issue

Assume we have a Kotlin source, named Constants.kt, as follows:

const val FOO = "foo"

And a Java source:

class Bar {
    @Named(ConstantsKt.FOO) void set(/* */) { /* */ }
}

When @Named annotation (KSAnnotationJavaImpl) is resolved, it yields ["value:null"] from its arguments property, with no way to retrieve the "foo" value.

Named = javax.inject.Named for completeness.

So, basically, Kotlin constants are not properly resolved in Java annotation arguments.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Jeffsetcommented, Mar 7, 2022

Also this leaves us with the fundamental problem - how to model synthetic file facades in KSP, if they are used as classes directly, like in @SomeAnnotation(clazz = ConstantsKt.class). For now we are getting ErrorType there.

0reactions
Jeffsetcommented, Apr 16, 2022

Thanks for the fix!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin Annotations
If we need to specify that an annotation parameter may have multiple values, then we just pass an array of those values:
Read more >
Kotlin Annotation IntDef
So i have tried it, and made an annotation for this, but it won't show in autocompletion. My question: - Is Java annotation...
Read more >
Nullability in Java and Kotlin
Nullability is the ability of a variable to hold a null value. ... If your Java code doesn't have these annotations, then Kotlin...
Read more >
Improve code inspection with annotations
For example, if a local variable that contains a null value is passed as a parameter to a method with the @NonNull annotation...
Read more >
Chapter 10. Annotations and reflection - Kotlin in Action
For example, a Kotlin property corresponds to a Java field, a getter, and possibly a setter and its parameter. A property declared in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found