File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
main/java/com/uber/nullaway/generics
test/java/com/uber/nullaway/jspecify Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1919import com .sun .source .tree .NewArrayTree ;
2020import com .sun .source .tree .NewClassTree ;
2121import com .sun .source .tree .ParameterizedTypeTree ;
22+ import com .sun .source .tree .ParenthesizedTree ;
2223import com .sun .source .tree .Tree ;
2324import com .sun .source .tree .VariableTree ;
2425import com .sun .source .util .TreePath ;
@@ -584,7 +585,12 @@ public static void checkTypeParameterNullnessForConditionalExpression(
584585 ConditionalExpressionTree tree , VisitorState state ) {
585586 // hack: sometimes array nullability doesn't get computed correctly for a conditional expression
586587 // on the RHS of an assignment. So, look at the type of the assignment tree.
587- Tree parent = state .getPath ().getParentPath ().getLeaf ();
588+ TreePath parentPath = state .getPath ().getParentPath ();
589+ Tree parent = parentPath .getLeaf ();
590+ while (parent instanceof ParenthesizedTree ) {
591+ parentPath = parentPath .getParentPath ();
592+ parent = parentPath .getLeaf ();
593+ }
588594 if (parent instanceof AssignmentTree || parent instanceof VariableTree ) {
589595 return getTreeType (parent , state );
590596 }
Original file line number Diff line number Diff line change @@ -2045,6 +2045,21 @@ public void issue1093() {
20452045 .doTest ();
20462046 }
20472047
2048+ @ Test
2049+ public void issue1127 () {
2050+ makeHelper ()
2051+ .addSourceLines (
2052+ "Main.java" ,
2053+ "package com.uber;" ,
2054+ "import org.jspecify.annotations.Nullable;" ,
2055+ "public class Main {" ,
2056+ " void arrayAssign(boolean b, @Nullable String @Nullable [] vals) {" ,
2057+ " @Nullable String[] arr = (b ? vals : null);" ,
2058+ " }" ,
2059+ "}" )
2060+ .doTest ();
2061+ }
2062+
20482063 @ Test
20492064 public void nullUnmarkedGenericField () {
20502065 makeHelper ()
You can’t perform that action at this time.
0 commit comments