GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Ant task fails with Java17 · Issue #3593 · pmd/pmd

[core] Ant task fails with Java17 #3593

New issue
Copy link
New issue
Copy link
Closed
#3637
Closed
[core] Ant task fails with Java17#3593
#3637
Copy link
Assignees
adangel
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
6.41.0

Description

@linusjf
linusjf
opened on Oct 31, 2021
Issue body actions

Affects 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]

Activity

  1. linusjf
    added
    a:bugPMD crashes or fails to analyse a file.
    on Oct 31, 2021
  2. jsotuyod commented on Oct 31, 2021

    @jsotuyod
    jsotuyod
    on Oct 31, 2021
    Member
    More actions

    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

    pmd/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

    Line 207 in f18ceeb

    } catch (ReflectiveOperationException ignored) {
    and

    pmd/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java

    Line 221 in f18ceeb

    } catch (ReflectiveOperationException ignored) {
    while finally adding the reflective call on Console.charset() for JRE 17 should fix it…

    Reacted by Linus Fernandes
  3. linusjf commented on Oct 31, 2021

    @linusjf
    linusjf
    on Oct 31, 2021
    Author
    More actions

    Yes, it's Java 17. I ought to have mentioned that. My bad.

  4. adangel
    changed the title [-]Pmd ant task fails for 6.40.0 and 6.39.0[/-] [+][core] Ant task fails with Java17[/+] on Nov 1, 2021
  5. adangel
    added this to the 6.41.0 milestone on Nov 1, 2021
  6. adangel commented on Nov 1, 2021

    @adangel
    adangel
    on Nov 1, 2021
    Member
    More actions

    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.

  7. linusjf commented on Nov 1, 2021

    @linusjf
    linusjf
    on Nov 1, 2021
    Author
    More actions

    @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

  8. adangel
    self-assigned this
    on Nov 16, 2021
  9. adangel
    added a commit that references this issue on Nov 18, 2021

    [core] Fix Ant task with Java17

    This issue will close once commit f9b5b9a is merged into the 'main' branch.
    f9b5b9a
  10. adangel
    closed this as completedin f9b5b9aon Nov 26, 2021
  11. adangel
    closed this as completedin #3637on Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @adangel
    adangel

Labels

a:bugPMD crashes or fails to analyse a file.

Type

No type

Projects

No projects

    Milestone

    • 6.41.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.