in spring mvc (5.1.3) i'm trying to do:
val url : String? = null
val matcher: ResultMatcher = MockMvcResultMatchers.forwardedUrl(url)
and i get compilation error for the second line.
from intellij (kotlinc-jvm 1.3.11):
Error:(230, 56) Kotlin: Null can not be a value of a non-null type String
or from gradle (kotlin 1.2.71):
Type mismatch: inferred type is String? but String was expected
the java source code of spring method is:
/**
* Asserts the request was forwarded to the given URL.
* <p>This method accepts only exact matches.
* @param expectedUrl the exact URL expected
*/
public static ResultMatcher forwardedUrl(String expectedUrl) {
return result -> assertEquals("Forwarded URL", expectedUrl, result.getResponse().getForwardedUrl());
}
intellij displays javadoc:
org.springframework.test.web.servlet.result.MockMvcResultMatchers @NotNull
@Contract(pure = true)
public static org.springframework.test.web.servlet.ResultMatcher forwardedUrl(@Nullable String expectedUrl)
so why the compiler still requires non-nullable type and how to bypass that requirement?