Skip to content

Commit 55b15a2

Browse files
committed
Java: Add integration test for buildless lambda recovery
1 parent b0c8fcd commit 55b15a2

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[VALUE_NOT_IN_TYPE] predicate diagnostics(@diagnostic id, string generated_by, int severity, string error_tag, string error_message, string full_error_message, @location_default location): Value -16777184 of field location is not in type @location_default. The value is however in the following types: @diagnostic. Appears in tuple (-16777200,"CodeQL Java extractor",5,"","Failed to traverse method body at /private/var/folders/y2/gcxfwn2j4slfs8cnlt6bzsn40000gn/T/pytest-of-idrissrio/pytest-19/ql/java/ql/integration-tests/java/lambda-expression-buildless-recovery/test/test/Test.java:10:17:10:42","",-16777184)
2+
[VALUE_NOT_IN_TYPE] predicate diagnostic_for(@diagnostic diagnostic, @compilation compilation, int file_number, int file_number_diagnostic_number): Value -16777188 of field diagnostic is not in type @diagnostic. Appears in tuple (-16777188,-16777216,0,14)
3+
[VALUE_NOT_IN_TYPE] predicate diagnostic_for(@diagnostic diagnostic, @compilation compilation, int file_number, int file_number_diagnostic_number): Value -16777176 of field diagnostic is not in type @diagnostic. Appears in tuple (-16777176,-16777216,0,21)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| Frontend errors in file: (2 errors during annotation processing) | 2 |
2+
| Frontend errors in file: Test.java (7 javac errors) | 2 |
3+
| Unknown errors in file: Test.java (5) | 2 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Diagnostics/ExtractionErrors.ql
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// The import below is intentionally commented out to test buildless recovery.
2+
// import java.util.stream.Stream;
3+
4+
public class LambdaBuildlessRecoveryTest {
5+
6+
private Stream<String> getStringStream() {
7+
return getStringStream();
8+
}
9+
10+
public void testSimpleLambdaExpression() {
11+
int unused = 0;
12+
Stream<String> s = getStringStream();
13+
Stream<String> mapped = s.map(x -> x);
14+
mapped.forEach(System.out::println);
15+
}
16+
17+
public void testLambdaWithBlockBody() {
18+
int unused = 42;
19+
Stream<String> s = getStringStream();
20+
Stream<String> filtered = s.filter(item -> {
21+
int unused = 42;
22+
String proc = item.toUpperCase();
23+
return proc.length() > 0;
24+
});
25+
filtered.forEach(System.out::println);
26+
}
27+
28+
public void testVariableCapture() {
29+
int unused = 99;
30+
String prefix = "proc_";
31+
Stream<String> s = getStringStream();
32+
Stream<String> result = s.map(item -> prefix + item);
33+
result.forEach(System.out::println);
34+
}
35+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def test(codeql, java, use_java_17):
2+
codeql.database.create(
3+
build_mode="none",
4+
source_root="."
5+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| Test.java:11:9:11:23 | int unused |
2+
| Test.java:13:9:13:46 | Stream<String> mapped |
3+
| Test.java:18:9:18:24 | int unused |
4+
| Test.java:20:9:24:11 | Stream<String> filtered |
5+
| Test.java:29:9:29:24 | int unused |
6+
| Test.java:30:9:30:32 | String prefix |
7+
| Test.java:32:9:32:61 | Stream<String> result |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
from LocalVariableDecl v
4+
where not exists(v.getAnAccess()) and exists(v.getFile().getRelativePath())
5+
select v

0 commit comments

Comments
 (0)