mirror of
https://github.com/github/codeql.git
synced 2026-04-24 00:05:14 +02:00
Add test for ObjFlow over binding patterns
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
public class Test {
|
||||
|
||||
interface Intf { }
|
||||
static class Specific implements Intf { public String toString() { return "Specific"; } }
|
||||
static class Alternative implements Intf { public String toString() { return "Alternative"; } }
|
||||
|
||||
public static String caller() {
|
||||
|
||||
Alternative a = new Alternative(); // Instantiate this somewhere so there are at least two candidate types in general
|
||||
return test(new Specific());
|
||||
|
||||
}
|
||||
|
||||
public static String test(Object o) {
|
||||
|
||||
if (o instanceof Object o2) {
|
||||
// So we should know o2.toString is really Specific.toString():
|
||||
return o2.toString();
|
||||
}
|
||||
|
||||
switch (o) {
|
||||
case Object o2 when o2.hashCode() > 0 -> { return o2.toString(); } // Same goes for this `o2`
|
||||
default -> { return "Not an Intf"; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
//semmle-extractor-options: --javac-args --release 21
|
||||
@@ -0,0 +1,9 @@
|
||||
| Test.java:1:14:1:17 | super(...) | java.lang.Object.Object |
|
||||
| Test.java:4:16:4:23 | super(...) | java.lang.Object.Object |
|
||||
| Test.java:5:16:5:26 | super(...) | java.lang.Object.Object |
|
||||
| Test.java:9:21:9:37 | new Alternative(...) | Test$Alternative.Alternative |
|
||||
| Test.java:10:12:10:31 | test(...) | Test.test |
|
||||
| Test.java:10:17:10:30 | new Specific(...) | Test$Specific.Specific |
|
||||
| Test.java:18:14:18:26 | toString(...) | Test$Specific.toString |
|
||||
| Test.java:22:27:22:39 | hashCode(...) | java.lang.Object.hashCode |
|
||||
| Test.java:22:57:22:69 | toString(...) | Test$Specific.toString |
|
||||
@@ -0,0 +1,7 @@
|
||||
import java
|
||||
|
||||
import semmle.code.java.dispatch.VirtualDispatch
|
||||
|
||||
from Call c, Callable c2
|
||||
where c2 = viableCallable(c)
|
||||
select c, c2.getQualifiedName()
|
||||
Reference in New Issue
Block a user