Skip to content

[java] Support JDK 22#4824

Merged
adangel merged 13 commits into
pmd:masterfrom
adangel:issue-4794-java-22
Mar 4, 2024
Merged

[java] Support JDK 22#4824
adangel merged 13 commits into
pmd:masterfrom
adangel:issue-4794-java-22

Conversation

@adangel

@adangel adangel commented Feb 15, 2024

Copy link
Copy Markdown
Member

Describe the PR

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

- 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".
@adangel adangel added this to the 7.0.0 milestone Feb 15, 2024
@ghost

ghost commented Feb 15, 2024

Copy link
Copy Markdown
1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 17 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 1 errors and 0 configuration errors.
Download full report as build artifact
Compared to master:
This changeset changes 0 violations,
introduces 17 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 1 errors and 0 configuration errors.
Download full report as build artifact

Generated by 🚫 Danger

@adangel adangel marked this pull request as ready for review February 15, 2024 16:05
Comment on lines +216 to +228
// 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.
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

private static void setDefaultCharset(String charsetName) {
System.setProperty("file.encoding", charsetName);
}
@Test
void testFormatterEncodingWithXML() throws Exception {
Locale.setDefault(Locale.FRENCH);
setDefaultCharset("cp1252");
executeTarget("testFormatterEncodingWithXML");
String report = IOUtil.readFileToString(currentTempFile(), StandardCharsets.UTF_8);
assertTrue(report.contains("someVariableWithÜmlaut"));
}
@Test
void testFormatterEncodingWithXMLConsole() throws UnsupportedEncodingException {
setDefaultCharset("cp1252");
String report = executeTarget("testFormatterEncodingWithXMLConsole");
assertTrue(report.startsWith("<?xml version=\"1.0\" encoding=\"windows-1252\"?>"));
assertTrue(report.contains("someVariableWithÜmlaut"));
}

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.

@adangel adangel merged commit 93bf4d5 into pmd:master Mar 4, 2024
adangel added a commit that referenced this pull request Mar 4, 2024
@adangel adangel deleted the issue-4794-java-22 branch March 4, 2024 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] Support JDK 22

2 participants