-
Notifications
You must be signed in to change notification settings - Fork 438
Fix: Report unboxing.of.nullable in conditional expressions with primitive result #7433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Suvrat1629
wants to merge
6
commits into
typetools:master
Choose a base branch
from
Suvrat1629:false-neg-6849
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0994c6a
ternary false negative fix
Suvrat1629 f60011f
change
Suvrat1629 164f5e6
Merge ../checker-framework-branch-master into false-neg-6849
mernst 9ff5e03
Merge ../checker-framework-branch-master into false-neg-6849
mernst 382b23b
Merge ../checker-framework-branch-master into false-neg-6849
mernst 8ba7018
Put error message key in brackets
mernst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import java.util.*; | ||
| import org.checkerframework.checker.nullness.qual.*; | ||
|
|
||
| public class Issue6849 { | ||
|
|
||
| public static <T> T m(List<T> lst) { | ||
| return lst.get(0); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| List<@Nullable Integer> lst = new LinkedList<>(); | ||
| lst.add(null); | ||
| // :: error: [unboxing.of.nullable] | ||
| int y = ((true) ? Issue6849.<@Nullable Integer>m(lst) : 10); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Logic is correct; consider using the existing helper method for consistency.
The fix correctly identifies when javac implicitly unboxes a reference-typed operand in a conditional expression with a primitive result type and reports
unboxing.of.nullablewhen appropriate. The early return pattern is consistent withvisitTypeCast(lines 509-513).Minor suggestion: The existing
isPrimitive(ExpressionTree)helper method (lines 714-716) could be reused for slightly more readable and consistent code.♻️ Suggested refactor to use existing helper
if (type.getKind().isPrimitive()) { ExpressionTree trueExpr = tree.getTrueExpression(); ExpressionTree falseExpr = tree.getFalseExpression(); - boolean trueNeedsUnboxing = !TypesUtils.isPrimitive(TreeUtils.typeOf(trueExpr)); - boolean falseNeedsUnboxing = !TypesUtils.isPrimitive(TreeUtils.typeOf(falseExpr)); + boolean trueNeedsUnboxing = !isPrimitive(trueExpr); + boolean falseNeedsUnboxing = !isPrimitive(falseExpr); if (trueNeedsUnboxing) {📝 Committable suggestion
🤖 Prompt for AI Agents