Repository navigation
[pulse] do not continue past the Kotlin intrinsics that always throw - #2340
Merged
dulmarod merged 1 commit intoDec 2, 2026
Merged
Conversation
Contributor
|
I think we should trim the comment. |
`kotlin.jvm.internal.Intrinsics` has a family of static methods that never return, which
kotlinc emits for the language's own checks. They are library bytecode, so with no model the
call is unknown, it returns, and the path carries on. Reading a `lateinit` property is the
costly case: it compiles to "load the field; if it is non-null jump over; otherwise call
`throwUninitializedPropertyAccessException`; push null", so a path continuing past the thrower
reaches that pushed null, and every such read was reported as a null dereference.
class C {
lateinit var r: Repo
fun read() = r.use() // reported NULLPTR_DEREFERENCE on the compiler's own null
}
Only the throwers whose failure the analysis cannot reason about are modelled. The
`checkNotNull` family is deliberately left alone, even though it has the same contract as
Guava's `Preconditions.checkNotNull`, which is modelled right above it as pruning its argument
non-null. Pruning makes the null branch unsatisfiable, so Pulse drops the disjunct rather than
reporting it, and the two members of the family that matter are not assertions the programmer
made: kotlinc emits `checkNotNull` for an implicit platform-type coercion as well as for `x!!`,
and emits `checkNotNullParameter` at the head of every function with a non-null formal. Both
carry Java-to-Kotlin null flows. Modelling them costs, in this suite alone,
`Kotlin.passNullFromJavaWhenDisallowedBad` and all six `BasicJavaKotlinBoundary` NULL_ARGUMENT
findings. `throwNpe`/`throwJavaNpe` are the pre-1.4 compilation of the same two constructs and
are left out for the same reason.
Limitations: a `lateinit` property that genuinely is never assigned is now not reported either.
A `!!` whose value Pulse can see is null is still reported at the dereference past the check
rather than at the assertion; separating that from the platform-type coercion would need source
information the bytecode does not carry, since kotlinc compiles both to the same instruction.
## Test plan
New `codetoanalyze/kotlin/pulse/Lateinit.kt`: the `lateinit` read is silent, while `!!` on a
null local, `!!` on a null field and passing null to a non-null parameter still report.
VladimirMakaev
force-pushed
the
pr/pulse-kotlin-intrinsics-1126
branch
from
December 1, 2026 22:47
38ad901 to
a9b4ca6
Compare
Contributor
Author
|
Trimmed the Intrinsics comment to two lines; the models and test expectations are unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
kotlin.jvm.internal.Intrinsicshas a family of static methods that never return, whichkotlinc emits for the language's own checks. They are library bytecode, so with no model the
call is unknown, it returns, and the path carries on. Reading a
lateinitproperty is thecostly case: it compiles to "load the field; if it is non-null jump over; otherwise call
throwUninitializedPropertyAccessException; push null", so a path continuing past the throwerreaches that pushed null, and every such read was reported as a null dereference.
Only the throwers whose failure the analysis cannot reason about are modelled. The
checkNotNullfamily is deliberately left alone, even though it has the same contract asGuava's
Preconditions.checkNotNull, which is modelled right above it as pruning its argumentnon-null. Pruning makes the null branch unsatisfiable, so Pulse drops the disjunct rather than
reporting it, and the two members of the family that matter are not assertions the programmer
made: kotlinc emits
checkNotNullfor an implicit platform-type coercion as well as forx!!,and emits
checkNotNullParameterat the head of every function with a non-null formal. Bothcarry Java-to-Kotlin null flows. Modelling them costs, in this suite alone,
Kotlin.passNullFromJavaWhenDisallowedBadand all sixBasicJavaKotlinBoundaryNULL_ARGUMENTfindings.
throwNpe/throwJavaNpeare the pre-1.4 compilation of the same two constructs andare left out for the same reason.
Limitations: a
lateinitproperty that genuinely is never assigned is now not reported either.A
!!whose value Pulse can see is null is still reported at the dereference past the checkrather than at the assertion; separating that from the platform-type coercion would need source
information the bytecode does not carry, since kotlinc compiles both to the same instruction.
Test plan
New
codetoanalyze/kotlin/pulse/Lateinit.kt: thelateinitread is silent, while!!on anull local,
!!on a null field and passing null to a non-null parameter still report.