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
Java Exception breakpoint fires for NPE in JSON library ArrayPools.kt in the try-catch environment.
This has no other negative effects because the NPE is suppressed:
packagekotlinx.serialization.json.internal/* * Not really documented kill switch as a workaround for potential * (unlikely) problems with memory consumptions.*/privatevalMAX_CHARS_IN_POOL= runCatching {
System.getProperty("kotlinx.serialization.json.pool.size").toIntOrNull()
}.getOrNull() ?:2*1024*1024
In most cases the property is not set, it's not even documented. As result, Kotlin NullPointerException is on the main path for all JSON-write operations: getProperty("...").toIntOrNull()
I suggest we should not use the try-catch to handle the expected NPE, but instead use a null-safe call:
Indeed, to improve readability the additional processing of the null should be added.
However, this exception does not have a significant impact on performance, because the value is initialized once, when the variable MAX_CHARS_IN_POOL is accessed for the first time.
You can verify this if you refer to the stacktrace, in which runCatching is called from the <clinit> of class ArrayPoolsKt, which is executed once when loading the class into the JVM.
Describe the bug
Java Exception breakpoint fires for NPE in JSON library
ArrayPools.kt
in the try-catch environment.This has no other negative effects because the NPE is suppressed:
In most cases the property is not set, it's not even documented. As result, Kotlin NullPointerException is on the main path for all JSON-write operations:
getProperty("...").toIntOrNull()
I suggest we should not use the try-catch to handle the expected NPE, but instead use a null-safe call:
To Reproduce
Expected behavior
No preventable NPE should be thrown.
Environment
The text was updated successfully, but these errors were encountered: