Repository navigation
[java] align parameter annotations with the parameters they belong to - #2352
Open
VladimirMakaev wants to merge 2 commits into
Open
VladimirMakaev wants to merge 2 commits into
VladimirMakaev wants to merge 2 commits into
Conversation
VladimirMakaev
marked this pull request as ready for review
December 2, 2026 11:25
A method's parameter annotations are indexed against its source parameter list, which leaves out
the synthetic parameters the descriptor begins with: the outer instance of an inner class, and
the name and ordinal of an enum constructor. Reading them in order put each annotation on the
parameter before the one it was written for, so a nullable parameter inherited its neighbour's
non-null requirement. The synthetic constructor that supplies default arguments passes null for
a defaulted nullable parameter, and that null then met a requirement that was never written.
class Outer(val tag: String) {
// reported: null passed where non-null was expected, on the constructor the compiler
// generates for the defaults
inner class Event(val id: String? = null, val origin: Origin = Origin.UNKNOWN)
}
Annotations are now matched to the end of the parameter list, which is where the two lists agree.
A method whose counts already agree is unaffected.
## Test plan
kotlin/pulse/DefaultArguments.kt is a silent guard in source capture. In compiled-output
capture, the false null argument disappears and both non-null controls report. Java Pulse
and Kotlin resources are unchanged; Kotlin Pulse retains its two existing lambda-naming
trace differences.
…g the compiler A build system that hands Infer a library's compiled classes gives the analysis a different program from one that runs the compiler under Infer: the compiler's own helpers stay outside the capture. Several Kotlin shapes only report in that mode, so the fixtures for them are silent in the other Kotlin tests and there is nowhere to pin them. This adds a case that compiles its sources and then captures the classes through --generated-classes. Its first fixture is the inner class whose default-arguments constructor passes null for a defaulted nullable parameter. Without the parameter-annotation alignment that fixture reports a null argument that cannot happen, and the two controls beside it -- a null that really does reach a parameter declared non-null, through the ordinary and the default-arguments constructor -- report nothing at all. With it, the first is silent and both controls report. ## Test plan The new case, and the Kotlin and Java suites.
VladimirMakaev
force-pushed
the
cut-kotlin-capture
branch
from
December 2, 2026 17:01
7134c5e to
10b2dfd
Compare
This branch has not been deployed
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.
A method's parameter annotations are indexed against its source parameter list, which leaves out the synthetic parameters the descriptor begins with: the outer instance of an inner class, and the name and ordinal of an enum constructor. Reading them in order put each annotation on the parameter before the one it was written for, so a nullable parameter inherited its neighbour's non-null requirement. The synthetic constructor that supplies default arguments passes null for a defaulted nullable parameter, and that null then met a requirement that was never written.
Annotations are now matched to the end of the parameter list, which is where the two lists agree. A method whose counts already agree is unaffected.
The report only appears when Infer is given a library's compiled classes instead of running the compiler under it, so the second commit adds a Kotlin case that compiles its sources and then captures the classes through
--generated-classes. Its fixture is the inner class above. Without the first commit it reports the impossible null, and its two controls, a null that really does reach a parameter declared non-null through the ordinary and the default-arguments constructor, report nothing. With it, the fixture is silent and both controls report.Test plan
With Kotlin 2.4.21 and JDK 21: the new jar-capture case passes, and fails as described without the first commit. The Kotlin resources and Java pulse suites pass. The Kotlin pulse suite differs from its expectations only in two lambda names in TAINT_ERROR traces (
$lambda$1vs$lambda$0); the parent commit shows the same difference with this compiler.