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.

Add Kotlin nullable type support for `AnnotatedService` arguments

See original GitHub issue

Currently, AnnotatedService requires @Nullable annotations(or Optional) to allow null values for method parameters even when it’s used with Kotlin which offers nice null-safety with nullable types.

Example:

@Get("/foo")
fun foo(@Nullable @Param("bar") bar: String?): HttpResponse {
    // ...
}

Even though Kotlin nullable types(?), when compiled to java code, is attached @org.jetbrains.annotations.Nullable annotations, its retention policy is CLASS, which makes it invisible at Java Runtime.

kotlin-reflect seems to be the best bet to make this work.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ks-yimcommented, Mar 16, 2022

@ikhoon

Otherwise, is there another API that is only available in Kotlin at runtime time?

I was thinking of using isMarkedNullable API of KType.

I don’t know how exactly isMarkedNullable API works at runtime(maybe by looking at @Metadata annotation values), but we can get nullability of function parameters at runtime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nullability in Java and Kotlin
This guide covers support for nullable types in Kotlin, how Kotlin treats nullable annotations from Java, and more.
Read more >
Nullable types in kotlin annotation processor - Stack Overflow
Type annotations can target type of anything: type of local variable ... won't work at all times (such as in case of nested...
Read more >
Add nullability annotations also to generic type variables and ...
I'd like to wait for feedback from the Kotlin community, e.g. Remove @Nullable annotation from ResultQuery.fetchSingleInto(Class) and Record.into(Class) ...
Read more >
Improve code inspection with annotations - Android Developers
Add @Nullable and @NonNull annotations to check the nullness of a given variable, parameter, or return value. The @Nullable annotation indicates a variable, ......
Read more >
@Nullable and @NotNull | IntelliJ IDEA Documentation
When you compile your project, the IDE adds assertions to all methods and parameters annotated with the @NotNull annotation. The assertions will ...
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