Java: Add integration test for buildless lambda recovery

This commit is contained in:
idrissrio
2025-10-07 16:50:07 +02:00
parent b0c8fcda35
commit 55b15a261a
7 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
[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)
[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)
[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)

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,7 @@
| Test.java:11:9:11:23 | int unused |
| Test.java:13:9:13:46 | Stream<String> mapped |
| Test.java:18:9:18:24 | int unused |
| Test.java:20:9:24:11 | Stream<String> filtered |
| Test.java:29:9:29:24 | int unused |
| Test.java:30:9:30:32 | String prefix |
| Test.java:32:9:32:61 | Stream<String> result |

View File

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