not sure if bug or I'm missing something I am gett...
# announcements
i
not sure if bug or I'm missing something I am getting warnings on this code
Copy code
result.andExpect(status().isOk)
    .andReturn()
    .response!! // Problematic line
    .contentAsClass<SomeType>()

inline fun <reified T> MockHttpServletResponse.contentAsClass(): T? =
    TestUtil.convertJsonBytesToObject(this.contentAsString, T::class.java) // This returns T
with
!!
Copy code
Unnecessary non-null assertion (!!) on a non-null receiver of type MockHttpServletResponse!
without
!!
Copy code
Call of inline function with nullable extension receiver can provoke NPE in Kotlin 1.2+
method
org.springframework.test.web.servlet.MvcResult.getResponse()
has this docs/signature
Copy code
/**
 * Return the resulting response.
 * @return the response, never {@code null}
 */
MockHttpServletResponse getResponse();
I'm using current Kotlin & plugin - 1.3.71 any ideas or should I open issue?
👀 1
d
Maybe try on Kotlin 1.4-M1?
Or maybe change the extension function to work on
MockHttpServletResponse?
a
This is definitely a bug, for now you can suppress the warning "Call of inline function" with
@Suppress("PlatformExtensionReceiverOfInline")
. I will investigate this further.
🤩 1