https://kotlinlang.org logo
#getting-started
Title
# getting-started
b

Brutus5000

10/12/2020, 8:54 AM
I can compile the following code which at runtime will always end up with an NPE (getTransition returns null)
Copy code
@Test
    fun reproducibleNPE() {
        ZoneId.of("Europe/Berlin").rules.getTransition(LocalDateTime.MIN).isOverlap
    }
Looks like I can't trust Java platform calls. But what are the rules? When can I trust it?
m

Mranders

10/12/2020, 9:27 AM
This is explained in https://kotlinlang.org/docs/reference/java-interop.html#null-safety-and-platform-types In your case, looking at the Javadoc: • https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#getRules-- specifies that the return value is never null, so you can access this safely with .https://docs.oracle.com/javase/8/docs/api/java/time/zone/ZoneRules.html#getTransition-java.time.LocalDateTime- specifies that the returned value might be null, so you have to access this using ?.
b

Brutus5000

10/12/2020, 9:37 AM
Thank you
2 Views