GeezerVison is showing github.com — [core] Ant task fails with Java17 · Issue #3593 · pmd/pmd
[core] Ant task fails with Java17 #3593Labels a:bugPMD crashes or fails to analyse a file. DescriptionAffects PMD Version:
6.39.0 and 6.40.0
Description:
PMD ant task fails with version 6.39.0 and 6.40.0.
Exception Stacktrace:
pmd:
BUILD FAILED
/root/LearnJava/Switch/build.xml:240: java.lang.IllegalArgumentException: Cannot locate declared field class java.io.Console.cs
at org.apache.commons.lang3.Validate.isTrue(Validate.java:158)
at org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField(FieldUtils.java:510)
at net.sourceforge.pmd.ant.Formatter.getConsoleEncoding(Formatter.java:203)
at net.sourceforge.pmd.ant.Formatter.start(Formatter.java:76)
at net.sourceforge.pmd.ant.internal.PMDTaskImpl.doTask(PMDTaskImpl.java:125)
at net.sourceforge.pmd.ant.internal.PMDTaskImpl.execute(PMDTaskImpl.java:279)
at net.sourceforge.pmd.ant.PMDTask.execute(PMDTask.java:50)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.apache.tools.ant.Main.runBuild(Main.java:818)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
**Steps to reproduce
Running PMD through: *[ Ant] Activityjsotuyod commented on Oct 31, 2021 My guess is that this is not related to the version of PMD, but the version of the JRE in use… My guess is that you are Java 17?
Still, I'm a little surprised Apache Commons seems be throwing a IllegalArgumentException instead of a ReflectiveOperationException (which the code expects and handles). So modifying the catches
|
} catch (ReflectiveOperationException ignored) { |
and
|
} catch (ReflectiveOperationException ignored) { |
while finally adding the reflective call on Console.charset() for JRE 17 should fix it… Reacted by Linus Fernandes linusjf commented on Oct 31, 2021 Yes, it's Java 17. I ought to have mentioned that. My bad. changed the title [-]Pmd ant task fails for 6.40.0 and 6.39.0[/-] [+][core] Ant task fails with Java17[/+] on Nov 1, 2021adangel commented on Nov 1, 2021 Thanks for reporting!
This case doesn't seem to be covered by tests. I tried to build PMD with java17, but unfortunately, this problem is not triggered - for one, because there is not test case. But even with a test case that uses toConsole=true, it's not triggered, because the JUnit-Tests run without console - so System.console() returns null and we don't run into this situation.
This requires a bit more thinking on how we can actually test this.
Maybe we can add a integration test to https://github.com/pmd/pmd/tree/master/pmd-dist/src/test/java/net/sourceforge/pmd/it to also cover ant. There we can use different java versions to run the tests (we currently run java7 + java11). I think, we should make sure here to use all the current LTS versions (8, 11, 17) of Java for the tests. linusjf commented on Nov 1, 2021 @adangel I haven't been using PMD for a while. And since I'm executing this on Arch Linux for Termux which has rolling updates, Java 17 is the jre of choice on system updates enabled using pacman -Syu.
Initially, I thought this had something to do with modules. I haven't investigated further. Google-java-format had to be updated to export Sun's internal modules. The build.xml is available at
https://github.com/Fernal73/LearnJava/blob/master/Switch/build.xml added a commit that references this issue on Nov 18, 2021This issue will close once commit f9b5b9a is merged into the 'main' branch.f9b5b9a
MetadataMetadataa:bugPMD crashes or fails to analyse a file. DevelopmentNo branches or pull requestsIssue actions
|