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

[java] StackOverflowError with recursively bound type variable #5096

Closed
slovdahl opened this issue Jul 2, 2024 · 4 comments · Fixed by #5387
Closed

[java] StackOverflowError with recursively bound type variable #5096

slovdahl opened this issue Jul 2, 2024 · 4 comments · Fixed by #5387
Labels
a:bug PMD crashes or fails to analyse a file.
Milestone

Comments

@slovdahl
Copy link

slovdahl commented Jul 2, 2024

Affects PMD Version: 7.0.0, 7.1.0, 7.2.0, 7.3.0

Description:

I'm trying to upgrade PMD from 6.55.0 to 7.x but the PMD runs just end up in java.lang.StackoverflowErrrors.

ruleset.xml

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="PMD ruleset"
         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

  <description>PMD ruleset</description>

  <rule ref="category/java/bestpractices.xml/MissingOverride"/>
  <rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation"/>
  <rule ref="category/java/bestpractices.xml/ReplaceVectorWithList"/>
  <rule ref="category/java/bestpractices.xml/UseStandardCharsets"/>
  <rule ref="category/java/codestyle.xml/ExtendsObject"/>
  <rule ref="category/java/codestyle.xml/PackageCase"/>
  <rule ref="category/java/codestyle.xml/UnnecessaryCast"/>
  <rule ref="category/java/codestyle.xml/UnnecessarySemicolon"/>
</ruleset>

But also fails with just one of the rules in place.

Gradle configuration:

apply plugin: 'pmd'

pmd {
    toolVersion = '7.3.0'
    consoleOutput = true
    incrementalAnalysis = true
    ruleSets = [ "$rootProject.projectDir/gradle/pmd/ruleset.xml" ]
}

gradle.properties:

org.gradle.parallel=true
org.gradle.jvmargs=-Xmx3g

Tested with both Temurin 17 and 21 (the project requires at least 17) on Ubuntu 22.04.

Exception Stacktrace:

The topmost part of the stack trace inline, here is the full stack trace.

Caused by: java.lang.StackOverflowError
        at net.sourceforge.pmd.lang.java.types.Substitution.apply(Substitution.java:45)
        at net.sourceforge.pmd.lang.java.types.Substitution.apply(Substitution.java:28)
        at net.sourceforge.pmd.lang.java.types.SubstVar.subst(SubstVar.java:25)
        at net.sourceforge.pmd.lang.java.types.WildcardTypeImpl.subst(WildcardTypeImpl.java:35)
        at net.sourceforge.pmd.lang.java.types.WildcardTypeImpl.subst(WildcardTypeImpl.java:17)
        at net.sourceforge.pmd.lang.java.types.TypeOps.lambda$subst$0(TypeOps.java:950)
        at net.sourceforge.pmd.lang.java.types.TypeOps.mapPreservingSelf(TypeOps.java:977)
        at net.sourceforge.pmd.lang.java.types.TypeOps.subst(TypeOps.java:950)
        at net.sourceforge.pmd.lang.java.types.JClassType.subst(JClassType.java:78)
        at net.sourceforge.pmd.lang.java.types.JClassType.subst(JClassType.java:54)
        at net.sourceforge.pmd.lang.java.types.TypeOps.subst(TypeOps.java:941)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:213)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:154)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:152)
        at net.sourceforge.pmd.lang.java.types.TypeOps$SubtypeVisitor.isConvertible(TypeOps.java:662)
        at net.sourceforge.pmd.lang.java.types.TypeOps$SubtypeVisitor.isConvertible(TypeOps.java:598)
        at net.sourceforge.pmd.lang.java.types.TypeOps.isConvertiblePure(TypeOps.java:415)
        at net.sourceforge.pmd.lang.java.types.TypeOps.mostSpecific(TypeOps.java:1757)
        at net.sourceforge.pmd.lang.java.types.Lub.glb(Lub.java:316)
        at net.sourceforge.pmd.lang.java.types.TypeSystem.glb(TypeSystem.java:723)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:227)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:154)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:152)
        at net.sourceforge.pmd.lang.java.types.TypeOps$SubtypeVisitor.isConvertible(TypeOps.java:662)
        at net.sourceforge.pmd.lang.java.types.TypeOps$SubtypeVisitor.isConvertible(TypeOps.java:598)
        at net.sourceforge.pmd.lang.java.types.TypeOps.isConvertiblePure(TypeOps.java:415)
        at net.sourceforge.pmd.lang.java.types.TypeOps.mostSpecific(TypeOps.java:1757)
        at net.sourceforge.pmd.lang.java.types.Lub.glb(Lub.java:316)
        at net.sourceforge.pmd.lang.java.types.TypeSystem.glb(TypeSystem.java:723)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:227)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:154)
        at net.sourceforge.pmd.lang.java.types.TypeConversion.capture(TypeConversion.java:152)
        at net.sourceforge.pmd.lang.java.types.TypeOps$SubtypeVisitor.isConvertible(TypeOps.java:662)
        at net.sourceforge.pmd.lang.java.types.TypeOps$SubtypeVisitor.isConvertible(TypeOps.java:598)
        at net.sourceforge.pmd.lang.java.types.TypeOps.isConvertiblePure(TypeOps.java:415)
        at net.sourceforge.pmd.lang.java.types.TypeOps.mostSpecific(TypeOps.java:1757)
        at net.sourceforge.pmd.lang.java.types.Lub.glb(Lub.java:316)
        at net.sourceforge.pmd.lang.java.types.TypeSystem.glb(TypeSystem.java:723)

Code Sample demonstrating the issue:

I cannot share the project as is, and I haven't yet been able to figure out what exactly triggers it. Any help in pinpointing the problematic class would be appreciated.

Steps to reproduce:

TBD.

Running PMD through: Gradle 8.8

@slovdahl slovdahl added the a:bug PMD crashes or fails to analyse a file. label Jul 2, 2024
@oowekyala
Copy link
Member

Can you run PMD with the system property pmd.error_recovery set to whatever value? This will log the StackoverflowError as a regular error and show you the name of the file that causes the error. I don't know how to set properties with gradle, but maybe you can download a release and run the CLI directly.

@slovdahl
Copy link
Author

slovdahl commented Jul 2, 2024

Thanks for the tip!

Just for future reference, I get the feeling this is not possible to do using Gradle right now. I tried with both ./gradlew -Dpmd.error_recovery=true :component:pmdMain and ./gradlew -Ppmd.error_recovery=true :component:pmdMain, but I'm not getting it logged as a normal error. I also tried modifying the pmd { .. } block and the pmdMain { .. } block, but AFAICT there is no support for configuring system properties for the forked JVM used for running PMD in this case.

In any case, I downloaded the raw PMD binary package and ran it against the component and immediately got the same StackoverflowError. 👍 And with PMD_JAVA_OPTS="-Dpmd.error_recovery" pmd-bin-7.3.0/bin/pmd check -d component/src/main/java/ -R gradle/pmd/ruleset.xml -f text I also get two files with StackOverflowError: null as the error in the output. Time is up for today, but I'll try to extract a minimal reproducer tomorrow.

@slovdahl
Copy link
Author

slovdahl commented Jul 3, 2024

Here's a minimal reproducer: https://github.com/slovdahl/pmd-stackoverflow-reproducer. PMD fails on just the Settings.java file, but I included the other files to have something that actually compiles and is valid Java.

@slovdahl slovdahl changed the title [java] StackoverflowError when upgrading from 6.55.0 to 7.3.0 [java] StackOverflowError when upgrading from 6.55.0 to 7.3.0 Jul 5, 2024
@DanySK
Copy link

DanySK commented Jul 30, 2024

@oowekyala oowekyala changed the title [java] StackOverflowError when upgrading from 6.55.0 to 7.3.0 [java] StackOverflowError with recursively bounded type variable Dec 4, 2024
DanySK added a commit to AlchemistSimulator/Alchemist that referenced this issue Dec 6, 2024
@adangel adangel changed the title [java] StackOverflowError with recursively bounded type variable [java] StackOverflowError with recursively bound type variable Dec 15, 2024
@adangel adangel added this to the 7.9.0 milestone Dec 15, 2024
adangel added a commit that referenced this issue Dec 15, 2024
…5387)

Merge pull request #5387 from oowekyala:issue5096-stackoverflow
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 19, 2024
renovate bot added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 19, 2024
* chore(deps): update plugin java-qa to v1.79.0

* style: temporary disable PMD until pmd/pmd#5096 is fixed

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Danilo Pianini <danilo.pianini@unibo.it>
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 19, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 19, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 20, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 20, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 20, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 20, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 21, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 22, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 23, 2024
DanySK pushed a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 23, 2024
## [32.54.0](32.53.0...32.54.0) (2024-12-23)

### Dependency updates

* **api-deps:** update alchemist to v36.0.12 ([#364](#364)) ([75f93a7](75f93a7))
* **deps:** update dependency com.google.guava:guava to v33.4.0-jre ([#346](#346)) ([a12563e](a12563e))
* **deps:** update dependency gradle to v8.12 ([#359](#359)) ([f7d9bbd](f7d9bbd))
* **deps:** update dependency semantic-release-preconfigured-conventional-commits to v1.1.117 ([#363](#363)) ([4400ac9](4400ac9))
* **deps:** update plugin java-qa to v1.79.0 ([#353](#353)) ([aeb6121](aeb6121)), closes [pmd/pmd#5096](pmd/pmd#5096)
* **deps:** update plugin multijvmtesting to v3.0.2 ([#360](#360)) ([4fa5881](4fa5881))
* **deps:** update plugin org.danilopianini.gradle-pre-commit-git-hooks to v2.0.18 ([#362](#362)) ([925fb8d](925fb8d))
* **deps:** update plugin publishoncentral to v7.0.2 ([#357](#357)) ([4b9a12f](4b9a12f))
* **deps:** update plugin publishoncentral to v7.0.3 ([#358](#358)) ([dfb2d80](dfb2d80))
* **deps:** update plugin publishoncentral to v7.0.4 ([#361](#361)) ([db8a86e](db8a86e))
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Dec 23, 2024
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 18, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 18, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 19, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 19, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 19, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 20, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 20, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 21, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 23, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 25, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 25, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 25, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 25, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 26, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 26, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 27, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Feb 28, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 1, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 1, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 4, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 4, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 6, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 6, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 7, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 7, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 8, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 10, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 10, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 10, 2025
DanySK added a commit to AlchemistSimulator/alchemist-fxui that referenced this issue Mar 10, 2025
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

Successfully merging a pull request may close this issue.

4 participants