You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original failure I encountered was from a @SpringBootTest. To simplify it for reproduction:
//Test.kt
@SpringBootTest
class Test {
@Autowired
private lateinit var bean: SomeClass
@Test
fun example() {
assertThat("a").isNotEqualTo(bean.getBeanProperty())
}
}
In the example, getBeanProperty() might return null, but if I replace bean.getBeanProperty() with null, spotbugs succeeded. That makes me wonder if it was complaining about the fact that bean object could be null. So I change to test a little to decouple it from Spring:
//Test.kt
class Test {
private lateinit var str: String
@Test
fun example() {
str.length
}
}
and it fails on the same error M C NP: Possible null pointer dereference of null in xxx.Test.example() Dereferenced at Test.kt:[line xx]
Even if I instantiate the object (but not in the same test function), it would still think the str could be null:
//Test.kt
class Test {
private lateinit var str: String
@BeforeEach
fun init() {str = "123"}
@Test
fun example() {
str.length
}
}
The text was updated successfully, but these errors were encountered:
gradle version: 8.9
spotbugs plugin version: 5.2.5
The original failure I encountered was from a
@SpringBootTest
. To simplify it for reproduction:In the example,
getBeanProperty()
might return null, but if I replacebean.getBeanProperty()
withnull
, spotbugs succeeded. That makes me wonder if it was complaining about the fact thatbean
object could be null. So I change to test a little to decouple it from Spring:and it fails on the same error
M C NP: Possible null pointer dereference of null in xxx.Test.example() Dereferenced at Test.kt:[line xx]
Even if I instantiate the object (but not in the same test function), it would still think the str could be null:
The text was updated successfully, but these errors were encountered: