NullTernary does not report a warning for the arrow-case form (default -> ...), but reports one for the equivalent yield block. Both forms are semantically identical and do not involve unboxing, so the warning on the yield block is a false positive.
public class NullTernarySwitch {
// arrow-case expression — NO warning
String fArrow(int n) {
return switch (n) {
case 0 -> "zero";
default -> (n % 2 == 0) ? "even" : null;
};
}
// block-case with yield — NullTernary is reported
String fYield(int n) {
return switch (n) {
case 0 -> "zero";
default -> {
yield (n % 2 == 0) ? "even" : null; // false positive
}
};
}
}
NullTernarydoes not report a warning for the arrow-case form (default -> ...), but reports one for the equivalentyieldblock. Both forms are semantically identical and do not involve unboxing, so the warning on the yield block is a false positive.