Repository navigation
Conversation
ContentCachingResponseWrapper.copyBodyToResponse(boolean) passed
`complete ? this.content.size() : this.contentLength` to
setContentLength(int). The unboxing of the nullable contentLength field
is safe: that branch runs only when complete is false, and the enclosing
`complete || this.contentLength != null` check has then established
that the field is non-null. NullAway does not correlate a boolean with
a null check, though, and the upcoming check for nullable operands
unboxed in a conditional expression reports the line:
`[NullAway] unboxing of a @nullable expression 'this.contentLength'`
Test the field directly in the conditional so that NullAway sees the
null check. The result is the same for every input, and the expression
stays int-typed, so no Integer is allocated.
Link: uber/NullAway#2005
Link: uber/NullAway#98
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
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.
This is not a bug fix. It rewrites one expression in
ContentCachingResponseWrapper.copyBodyToResponse(boolean)so that an upcoming NullAway check does not report a false positive there.uber/NullAway#2005 makes NullAway report a nullable boxed operand that is unboxed in a conditional expression of primitive type. With it, the NullAway CI job that builds Spring Framework against the snapshot fails on this line:
The unboxing is safe: the
this.contentLengthbranch runs only whencompleteis false, and the enclosingif (complete || this.contentLength != null)has then established that the field is non-null. NullAway does not correlate a boolean with a null check (uber/NullAway#98), so it treats the field as nullable after that condition.The rewrite tests the field in the conditional itself:
The result is the same for every input:
completestill yieldscontent.size(), and!completestill yieldscontentLength, which the outerifguarantees is non-null. The expression staysint-typed, so noIntegeris allocated; a variant that boxedcontent.size()was rejected for that reason.:spring-web:compileJava(which runs NullAway) andContentCachingResponseWrapperTestspass. A model of this method in NullAway with #2005 applied reports the original form and not the rewritten one.🤖 Generated with Claude Code