Skip to content
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

[core] A crash upon PMD initialization #4267

Closed
LynnBroe opened this issue Dec 21, 2022 · 3 comments
Closed

[core] A crash upon PMD initialization #4267

LynnBroe opened this issue Dec 21, 2022 · 3 comments
Labels
a:bug PMD crashes or fails to analyse a file.

Comments

@LynnBroe
Copy link
Contributor

Affects PMD Version:6.50.0

Description:

I run PMD to detect the following code example, and it crashed.

Exception Stacktrace:

Exception in thread "main" java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract java.lang.Class[] com.beust.jcommander.Parameter.validateValueWith() (Found data of type class java.lang.Class[class net.sourceforge.pmd.cli.PMDParameters$RulePriorityValidator])
	at java.base/sun.reflect.annotation.AnnotationTypeMismatchExceptionProxy.generateException(AnnotationTypeMismatchExceptionProxy.java:57)
	at java.base/sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:86)
	at com.sun.proxy.$Proxy1.validateValueWith(Unknown Source)
	at com.beust.jcommander.WrappedParameter.validateValueWith(WrappedParameter.java:64)
	at com.beust.jcommander.ParameterDescription.validateValueParameter(ParameterDescription.java:350)
	at com.beust.jcommander.ParameterDescription.validateDefaultValues(ParameterDescription.java:164)
	at com.beust.jcommander.ParameterDescription.init(ParameterDescription.java:157)
	at com.beust.jcommander.ParameterDescription.<init>(ParameterDescription.java:65)
	at com.beust.jcommander.JCommander.addDescription(JCommander.java:631)
	at com.beust.jcommander.JCommander.createDescriptions(JCommander.java:601)
	at com.beust.jcommander.JCommander.<init>(JCommander.java:252)
	at com.beust.jcommander.JCommander.<init>(JCommander.java:238)
	at com.beust.jcommander.JCommander.<init>(JCommander.java:230)
	at net.sourceforge.pmd.cli.PmdParametersParseResult.extractParameters(PmdParametersParseResult.java:104)
	at net.sourceforge.pmd.PMD.runPmd(PMD.java:452)
	at net.sourceforge.pmd.PMD.main(PMD.java:418)
	at /class/path/of/my/code

Code Sample demonstrating the issue:

@org.junit.jupiter.api.Test
void foo() {
    synchronized (this) {}
}

Steps to reproduce:
Directly use PMD to detect the code example.

Running PMD through: [Maven]

@LynnBroe LynnBroe added the a:bug PMD crashes or fails to analyse a file. label Dec 21, 2022
@jsotuyod
Copy link
Member

@LynnBroe thanks for the report. This has nothing to do with the actual code being analyzed, it's on PMD's startup, as it parses the CLI parameters… now, this is a little curious:

  • you claim to be running PMD through Maven, not the CLI, so CLI arg parsing shouldn't happen…
  • you claim to be running PMD through Maven, yet your edited stacktrace claims to include your own custom code…

Can we validate the report is accurate? I'd guess you are not using Maven, but invoking PMD from within your own code, and if that's the case, this is an issue on your codebase. More probably than not, you are using a different version of com.beust.jcommander than the one PMD uses, and the binary incompatibility is triggering this exception.

@jsotuyod jsotuyod changed the title [java] A crash bug about Test [core] A crash bug about Test Jan 16, 2023
@jsotuyod jsotuyod changed the title [core] A crash bug about Test [core] A crash upon PMD initialization Jan 16, 2023
@rfevang
Copy link

rfevang commented Apr 24, 2023

I see this error when running PMD in Bazel, if my jcommander version is newer than 1.64 (1.69 is broken, versions in between are not in maven central). I don't know whether the issue is in jcommander or pmd.

@jsotuyod
Copy link
Member

This is down to how the host tool integrates PMD. An incorrect classpath (ie: including non-compatible dependencies) is going to break and is outside our control.

Having said that, PMD 7 no longer uses jCommander, favoring PicoCli instead, and the CLI code is split away under a separate module that integrators can (and probably should) leave out integrating directly through PmdAnalysis (programatically) or the Ant task (ie: Gradle, Maven).

@jsotuyod jsotuyod closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file.
Projects
None yet
Development

No branches or pull requests

3 participants