Merge pull request #20595 from github/idrissrio/java-lambda

Java: Add integration test for buildless lambda recovery
This commit is contained in:
Idriss Riouak
2025-10-08 09:53:29 +02:00
committed by GitHub
6 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
| Frontend errors in file: (2 errors during annotation processing) | 2 |
| Frontend errors in file: Test.java (7 javac errors) | 2 |
| Unknown errors in file: Test.java (5) | 2 |

View File

@@ -0,0 +1 @@
Diagnostics/ExtractionErrors.ql

View File

@@ -0,0 +1,35 @@
// The import below is intentionally commented out to test buildless recovery.
// import java.util.stream.Stream;
public class LambdaBuildlessRecoveryTest {
private Stream<String> getStringStream() {
return getStringStream();
}
public void testSimpleLambdaExpression() {
int unused = 0;
Stream<String> s = getStringStream();
Stream<String> mapped = s.map(x -> x);
mapped.forEach(System.out::println);
}
public void testLambdaWithBlockBody() {
int unused = 42;
Stream<String> s = getStringStream();
Stream<String> filtered = s.filter(item -> {
int unused = 42;
String proc = item.toUpperCase();
return proc.length() > 0;
});
filtered.forEach(System.out::println);
}
public void testVariableCapture() {
int unused = 99;
String prefix = "proc_";
Stream<String> s = getStringStream();
Stream<String> result = s.map(item -> prefix + item);
result.forEach(System.out::println);
}
}

View File

@@ -0,0 +1,5 @@
def test(codeql, java, use_java_17):
codeql.database.create(
build_mode="none",
source_root="."
)

View File

@@ -0,0 +1,4 @@
| Test.java:11:9:11:23 | int unused |
| Test.java:18:9:18:24 | int unused |
| Test.java:21:13:21:28 | int unused |
| Test.java:29:9:29:24 | int unused |

View File

@@ -0,0 +1,5 @@
import java
from LocalVariableDecl v
where not exists(v.getAnAccess()) and exists(v.getFile().getRelativePath())
select v