maybe worth knowing, I am on kotlin `1.3.21` and t...
# getting-started
t
maybe worth knowing, I am on kotlin
1.3.21
and the base classes are from spring (maybe I can post in spring channel as well, but this seems more generally related to kotlin, spring is relevant only because I have no influence on how
enhance
is called, it has to accept `null`s)
a
Just a shot in the dark, you could annotate the parameters inside your java class with
@Nullable
t
I cannot,
HateoasSortHandlerMethodArgumentResolver
comes from a library.
@Nullable
would solve the issue though
r
@thanksforallthefish could you write what is happening at runtime?
t
the whole story is this code is used to handle pagination in http requests, thorugh a
sort
query parameter (which is optional). If no
sort
parameter is received, the framework (
spring-data
) calls the
enhance
method with
null
. does this answer you?
as a temporary solution, I am implementing
Blabla
in java eh eh
h
I think it is a Spring Problem: The entire package is annotated not nullable: https://github.com/spring-projects/spring-data-commons/blob/master/src/main/java/org/springframework/data/web/package-info.java That's why the Kotlin compiler won't let you
override
with nullable types.
r
@thanksforallthefish I'm asking what exactly is happening when spring calls this method - if it's an exception could you paste a stacktrace?
h
When Java code calls a Kotlin method with
null
where the Kotlin parameter is declared non-nullable, a
java.lang.IllegalArgumentException: Parameter specified as non-null is null
is thrown.
r
@hho that method is from UriComponentsContributor from a different package
no, i'm taking it back
h
yes, but it's overridden
i think the spring team just forgot to sprinkle some
@Nullable
on the parameters.
Actually, the
UriComponentsContributor
interface explicitly states that the parameters can never be
null
. So the annotations seem correct.
The question is then: Why does the framework call that method with `null`…
r
any idea which parameter is null ?
t
sorry, meetings here. anyway, the parameter
value
is nullable (https://github.com/spring-projects/spring-hateoas/blob/master/src/main/java/org/springframework/hateoas/server/mvc/UriComponentsContributor.java#L46), so I guess it is indeed a problem with spring data commons declaring the base class override (
HateoasSortHandlerMethodArgumentResolver
) non nullable
h
t
glad you shared, I was a couple of minutes away of pressing the create issue button