-
Notifications
You must be signed in to change notification settings - Fork 377
Closed
Description
JDK 22 introduced Unnamed Variables & Patterns. Currently, unnamed pattern variables do not seem to be supported in CFG construction. Test case from uber/NullAway#1168:
package org.example;
public class NullAwayDiscardError {
public sealed interface IntOrBool {}
public record WrappedInt(int a) implements IntOrBool {}
public record WrappedBoolean(boolean b) implements IntOrBool {}
public static void unwrap(IntOrBool i) {
switch(i) {
case WrappedInt(_) -> {}
case WrappedBoolean(_) -> {}
}
}
}
This causes NullAway to crash. I think the reason is that WrappedInt(_)
is represented as a DeconstructedPatternNode
, but the nested pattern ends up as null
. Here is the relevant code:
Lines 632 to 638 in 751f087
public Node visitDeconstructionPattern21(Tree deconstructionPatternTree, Void p) { | |
List<? extends Tree> nestedPatternTrees = | |
DeconstructionPatternUtils.getNestedPatterns(deconstructionPatternTree); | |
List<Node> nestedPatterns = new ArrayList<>(nestedPatternTrees.size()); | |
for (Tree pattern : nestedPatternTrees) { | |
nestedPatterns.add(scan(pattern, p)); | |
} |
Here when we scan the nested pattern
tree, it's an AnyPatternTree
, which is not handled in CFG construction, so scan
returns null
. Other code does not expect a null
nested pattern in a DeconstructedPatternNode
leading to the crash.
Metadata
Metadata
Assignees
Labels
No labels