Skip to content

Commit 28fe20e

Browse files
authored
Merge pull request #20595 from github/idrissrio/java-lambda
Java: Add integration test for buildless lambda recovery
2 parents 75a7507 + f69e5f5 commit 28fe20e

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| Test.java:11:9:11:23 | int unused |
2+
| Test.java:18:9:18:24 | int unused |
3+
| Test.java:21:13:21:28 | int unused |
4+
| Test.java:29:9:29:24 | int unused |
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)