[java] Support JDK 22#4824
Conversation
- Record patterns in enhanced for statements - parenthesized patterns These features have not been standardized.
- after 20-preview is gone - Note: DECONSTRUCTION_PATTERNS_IN_ENHANCED_FOR_STATEMENT is completely gone. This was only available for 20-preview and has been removed with 21.
TemplateFragment now has an attribute "content".
…ance Main Methods
This is now standardized.
Generated by 🚫 Danger |
Java 22 provides a real console from System.console() even if it is non-interactive. In that case, we need to check whether we have a terminal.
| // Since Java 22, this returns a console even for redirected streams. | ||
| // In that case, we need to check Console.isTerminal() | ||
| // See: JLine As The Default Console Provider (JDK-8308591) | ||
| try { | ||
| Boolean isTerminal = (Boolean) MethodUtils.invokeMethod(console, "isTerminal"); | ||
| if (!isTerminal) { | ||
| // stop here, we don't have an interactive console. | ||
| return null; | ||
| } | ||
| } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException ignored) { | ||
| // fall-through - we use a Java Runtime < 22. | ||
| } | ||
|
|
There was a problem hiding this comment.
I'd assume since our CLI progressbar uses JLine3 under the hood to detect terminal capabilities that it is safe and won't choke on this change… but did you have the chance to test it?
There was a problem hiding this comment.
This change is about how we determine the console encoding for ant, if the report should be output to the console (toConsole=true) - and when building PMD with Java 22, the (ant) unit tests failed, because then we couldn't override the encoding for testing purpose anymore and couldn't test various encoding combinations. The tests are actually in pmd-java:
pmd/pmd-java/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java
Lines 89 to 110 in 04c2c01
And we explicitly set the system property "file.encoding" in the unit test, so that we can "override" the encoding for the test. That didn't work anymore, because Java 22 now returns always a Console and the tests used then always the correct console encoding rather than the faked test encoding.
I actually didn't test PMD CLI with Java 22 - if I remember correctly, I only tested the build with Java 22 and eventually it works - that means the integration tests in pmd-dist were successful. However, I think we don't test the progress bar there.
Describe the PR
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)