-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTest.java
More file actions
75 lines (61 loc) · 2.25 KB
/
Copy pathTest.java
File metadata and controls
75 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
public class Test {
public static Object testFlowThroughSwitchStmt(String s, Integer i, boolean unknown) {
Object o = unknown ? s : i;
switch (o) {
case Integer i2 -> { return (Object)i2; }
default -> { return null; }
}
}
public static Object testFlowThroughSwitchExpr(String s, Integer i, boolean unknown) {
Object o = unknown ? s : i;
Object toRet = switch (o) {
case Integer i2 -> (Object)i2;
default -> null;
};
return toRet;
}
public static Object testFlowThroughBindingInstanceOf(String s, Integer i, boolean unknown) {
Object o = unknown ? s : i;
if (o instanceof Integer i2)
return (Object)i2;
else
return null;
}
public static Object testFlowThroughSwitchStmtWrapper(Wrapper s, Wrapper i, boolean unknown) {
Wrapper o = unknown ? s : i;
switch (o) {
case Wrapper(Integer i2) -> { return (Object)i2; }
default -> { return null; }
}
}
public static Object testFlowThroughSwitchExprWrapper(Wrapper s, Wrapper i, boolean unknown) {
Wrapper o = unknown ? s : i;
Object toRet = switch (o) {
case Wrapper(Integer i2) -> (Object)i2;
default -> null;
};
return toRet;
}
public static Object testFlowThroughBindingInstanceOfWrapper(Wrapper s, Wrapper i, boolean unknown) {
Wrapper o = unknown ? s : i;
if (o instanceof Wrapper(Integer i2))
return (Object)i2;
else
return null;
}
public static <T> T source() { return null; }
public static void sink(Object o) { }
public static void test(boolean unknown, boolean unknown2) {
String source1 = source();
Integer source2 = source();
sink(testFlowThroughSwitchStmt(source1, source2, unknown));
sink(testFlowThroughSwitchExpr(source1, source2, unknown));
sink(testFlowThroughBindingInstanceOf(source1, source2, unknown));
Wrapper source1Wrapper = new Wrapper((String)source());
Wrapper source2Wrapper = new Wrapper((Integer)source());
sink(testFlowThroughSwitchStmtWrapper(source1Wrapper, source2Wrapper, unknown));
sink(testFlowThroughSwitchExprWrapper(source1Wrapper, source2Wrapper, unknown));
sink(testFlowThroughBindingInstanceOfWrapper(source1Wrapper, source2Wrapper, unknown));
}
record Wrapper(Object o) { }
}