-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Java: Add test for flexible constructor support #20136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: idrissrio/java-upgrade-fix
Are you sure you want to change the base?
Java: Add test for flexible constructor support #20136
Conversation
357ed2f
to
3667004
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a library test to verify Java extractor support for flexible constructor bodies, a new language feature introduced in JEP 513 and finalized in Java 25. The test validates that the extractor correctly handles constructors where statements can precede super() or this() calls.
Key changes:
- Creates a new test directory structure for flexible constructor testing
- Adds Java source code demonstrating various flexible constructor scenarios
- Configures the test to use Java 25 with preview features enabled
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
java/ql/test/library-tests/flexible-constructors/options | Configures extractor to use Java 25 with preview features |
java/ql/test/library-tests/flexible-constructors/PrintAst.qlref | References the AST printing query for test execution |
java/ql/test/library-tests/flexible-constructors/PrintAst.expected | Expected AST output for validation |
java/ql/test/library-tests/flexible-constructors/FlexibleConstructors.java | Test cases demonstrating flexible constructor syntax |
java/ql/test/library-tests/flexible-constructors/CONSISTENCY/diags.expected | Expected diagnostic output |
Comments suppressed due to low confidence (1)
java/ql/test/library-tests/flexible-constructors/options:2
- Java 25 does not exist as of my knowledge cutoff in January 2025. The latest stable Java version is Java 21 LTS, with Java 22 and 23 being non-LTS releases. Consider using an existing Java version or verify if this is intended for future testing.
//semmle-extractor-options: --javac-args --release 25 --enable-preview
The test ought to include field initialization (using both implicit and explicit |
fbb688a
to
eb51682
Compare
@@ -0,0 +1,2 @@ | |||
unexpectedDiagnostic | |||
| <compilation flexible-constructors.testproj/trap/java/diagnostics/diagnostic.trap.gz> | -1 | 0 | file://:0:0:0:0 | Unknown location for jdk.internal.RequiresIdentity+Annotation | Unknown location for jdk.internal.RequiresIdentity+Annotation | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This annotation is internally generated and has no specific source location. The issue is fixed in another PR (https://github.com/github/semmle-code/pull/53614/commits/ec9c0e744141ac02fbb1b62f3f5a4af2593168f1). The diags.expected
can be removed once this PR is rebased on top of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure what the unexpected diagnostic is about, otherwise LGTM.
Got a bit hasty with the approval there. I'd like to verify that we're not breaking implicit initializer calls. So we should have some tests for that. |
Extremely good point. I'll add a test for this. |
ca31ff6
to
9cf867e
Compare
So I see that the object initializer call is still put after the
I expect this will print |
Hi @aschackmull, I had to make some adjustments in the extractor for this (see the internal PR). |
Excellent, thanks for confirming. |
@@ -16,30 +16,6 @@ methodWithDuplicate | |||
| AbstractCollection<E> | removeAll | Collection<?> | | |||
| AbstractCollection<E> | retainAll | Collection<?> | | |||
| AbstractCollection<E> | toArray | T[] | | |||
| AbstractCollection<Entry<K,V>> | add | Entry<K,V> | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's with these kotlin test changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was related to the Java 25 upgrade. I had forgotten to update the merge target in the UI. I’ve fixed it now, and it no longer shows up.
Quick question about the kotlin qltest changes, which appear unrelated to this PR. Otherwise LGTM now. |
This PR adds a library test to verify the Java extractor support for flexible constructor bodies, a feature introduced in JEP 513 and finalized in Java 25..
Please ignore any DCA linked.