A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5006 below:

[java] Bad intersection, unrelated class types Child and Parent<? extends Child> · Issue #5006 · pmd/pmd · GitHub

Affects PMD Version:

7.1.0

Description:

An exception is thrown when processing code using generic wildcards and self-referential generic bounds. This bug does not occur if the parent type is declared as an interface.

class Parent<T extends Parent<T>> {} // Recursive type T

class Child extends Parent<Child> {}

class Box<T extends Parent<T>> {
  public void foo(Box<? extends Child> box) {} // <-- The bug is triggered by this line
}

Exception Stacktrace:

ContextedRuntimeException: java.lang.IllegalArgumentException: Bad intersection, unrelated class types Child and Parent<capture#225 of ? extends Child> in [Parent<capture#225 of ? extends Child>, Child]
Exception Context:
        [1:Rule applied on node=!debug only! [MethodDeclaration:309:15]public void foo(Box<? extends Child> box) {}]

org.apache.commons.lang3.exception.ContextedRuntimeException: java.lang.IllegalArgumentException: Bad intersection, unrelated class types Child and Parent<capture#225 of ? extends Child> in [Parent<capture#225 of ? extends Child>, Child]
Exception Context:
        [1:Rule applied on node=!debug only! [MethodDeclaration:309:15]public void foo(Box<? extends Child> box) {}]
---------------------------------
        at net.sourceforge.pmd.util.AssertionUtil.contexted(AssertionUtil.java:236)
        at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex(RuleApplicator.java:79)
        at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.apply(RuleApplicator.java:57)
        at net.sourceforge.pmd.lang.rule.internal.RuleSets.apply(RuleSets.java:155)
        at net.sourceforge.pmd.lang.impl.PmdRunnable.processSource(PmdRunnable.java:140)
        at net.sourceforge.pmd.lang.impl.PmdRunnable.run(PmdRunnable.java:80)
        at java.base@17.0.8.1/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base@17.0.8.1/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base@17.0.8.1/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base@17.0.8.1/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base@17.0.8.1/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: Bad intersection, unrelated class types Child and Parent<capture#225 of ? extends Child> in [Parent<capture#225 of ? extends Child>, Child]
        at net.sourceforge.pmd.lang.java.types.Lub.glb(Lub.java:344)
        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.TypeOps.isConvertible(TypeOps.java:462)
        at net.sourceforge.pmd.lang.java.types.TypeOps.isConvertible(TypeOps.java:401)
        at net.sourceforge.pmd.lang.java.types.JTypeMirror.isConvertibleTo(JTypeMirror.java:126)
        at net.sourceforge.pmd.lang.java.types.JTypeMirror.isSubtypeOf(JTypeMirror.java:114)
        at net.sourceforge.pmd.lang.java.types.TypeTestUtil.isA(TypeTestUtil.java:158)
        at net.sourceforge.pmd.lang.java.types.TypeTestUtil.isA(TypeTestUtil.java:178)
        at net.sourceforge.pmd.lang.java.types.TypeTestUtil.isA(TypeTestUtil.java:122)
        at net.sourceforge.pmd.lang.java.rule.xpath.internal.BaseContextNodeTestFun.lambda$makeCallExpression$1(BaseContextNodeTestFun.java:57)
        at net.sourceforge.pmd.lang.rule.xpath.internal.SaxonExtensionFunctionDefinitionAdapter$1.call(SaxonExtensionFunctionDefinitionAdapter.java:135)
        at net.sf.saxon.lib.ExtensionFunctionCall.effectiveBooleanValue(ExtensionFunctionCall.java:189)
        at net.sf.saxon.functions.IntegratedFunctionCall.effectiveBooleanValue(IntegratedFunctionCall.java:377)
        at net.sf.saxon.expr.elab.FallbackElaborator.lambda$elaborateForBoolean$3(FallbackElaborator.java:61)
        at net.sf.saxon.expr.FilterExpression$FilterExprElaborator$SimpleFilteredIterator.next(FilterExpression.java:1376)
        at net.sf.saxon.expr.ContextMappingIterator.next(ContextMappingIterator.java:67)
        at net.sf.saxon.functions.Count.count(Count.java:66)
        at net.sf.saxon.functions.Count$CountFnElaborator.lambda$elaborateForItem$0(Count.java:130)
        at net.sf.saxon.expr.ValueComparison$ValueComparisonElaborator.lambda$elaborateForItem$1(ValueComparison.java:546)
        at net.sf.saxon.expr.elab.ItemElaborator.lambda$elaborateForPull$0(ItemElaborator.java:36)
        at net.sf.saxon.expr.FilterExpression$FilterExprElaborator$PositionalFilteredIterator.next(FilterExpression.java:1330)
        at net.sourceforge.pmd.lang.rule.xpath.internal.SaxonXPathRuleQuery.evaluate(SaxonXPathRuleQuery.java:128)
        at net.sourceforge.pmd.lang.rule.xpath.XPathRule.apply(XPathRule.java:101)
        at net.sourceforge.pmd.lang.rule.RuleReference.apply(RuleReference.java:415)
        at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex(RuleApplicator.java:77)
        ... 9 more
Exception occurred on node !debug only! [MethodDeclaration:309:15]public void foo(Box<? extends Child> box) {}

Code Sample demonstrating the issue:

See above

Steps to reproduce:

Run PMD on the code sample

Running PMD through:

Gradle 8.5, on openjdk 17.0.8.1 2023-08-24


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4