Skip to content

Commit a1a885e

Browse files
committed
Java: Expand test.
1 parent 20661a3 commit a1a885e

File tree

2 files changed

+106
-33
lines changed

2 files changed

+106
-33
lines changed

java/ql/test/library-tests/dataflow/capture/B.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ void run() {
250250
}
251251

252252
void testInstanceInitializer() {
253+
// Tests capture in the instance initializer ("<obinit>")
253254
String s = source("init");
254255
class MyLocal3 {
255256
String f = s;
@@ -259,4 +260,23 @@ void run() {
259260
}
260261
new MyLocal3().run();
261262
}
263+
264+
void testConstructorIndirection() {
265+
// Tests capture in nested constructor call
266+
String s = source("init");
267+
class MyLocal4 {
268+
String f;
269+
MyLocal4() {
270+
this(42);
271+
}
272+
MyLocal4(int i) {
273+
f = s;
274+
}
275+
String get() {
276+
return this.f;
277+
}
278+
}
279+
sink(new MyLocal4().get()); // $ hasValueFlow=init
280+
sink(new MyLocal4(1).get()); // $ hasValueFlow=init
281+
}
262282
}

0 commit comments

Comments
 (0)