You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have encountered a crash while using generics and wildcards in the provided code snippet. The usage of these features seems to trigger an unexpected behavior, resulting in an exception when analyzed by PMD.
Code Sample demonstrating the issue:
publicclassSubClass<T> {
public <CextendsCollection<? superT>> Cinto(Ccollection) {
List<T> list = Arrays.asList((T[]) toArray());
collection.addAll(list);
returncollection;
}
}
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
pmd check -d SubClass.java -R category/java/bestpractices.xml -f text
Running PMD through:[CLI]
Exception Stacktrace:
org.apache.commons.lang3.exception.ContextedRuntimeException: java.lang.IllegalArgumentException: <? super T> cannot be a wildcard bound
Exception Context:
[1:Resolving type of=!debug only! [MethodCall:11:9]collection.addAll(list)]
[2:Rule applied on node=!debug only! [MethodCall:11:9]collection.addAll(list)]
---------------------------------
at net.sourceforge.pmd.util.AssertionUtil.contexted(AssertionUtil.java:232)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode.getTypeMirror(AbstractJavaTypeNode.java:54)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.getTypeMirror(ASTMethodCall.java:22)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode.getTypeMirror(AbstractJavaTypeNode.java:39)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.getTypeMirror(ASTMethodCall.java:22)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode.forceTypeResolution(AbstractJavaTypeNode.java:29)
at net.sourceforge.pmd.lang.java.ast.AbstractInvocationExpr.getOverloadSelectionInfo(AbstractInvocationExpr.java:27)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.getOverloadSelectionInfo(ASTMethodCall.java:22)
at net.sourceforge.pmd.lang.java.ast.InvocationNode.getMethodType(InvocationNode.java:48)
at net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil.isCallOnAssertionContainer(TestFrameworksUtil.java:166)
at net.sourceforge.pmd.lang.java.rule.bestpractices.JUnitAssertionsShouldIncludeMessageRule.visit(JUnitAssertionsShouldIncludeMessageRule.java:37)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.acceptVisitor(ASTMethodCall.java:75)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor(AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply(AbstractJavaRule.java:24)
at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex(RuleApplicator.java:75)
at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.apply(RuleApplicator.java:55)
at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:158)
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/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalArgumentException: <? super T> cannot be a wildcard bound
at net.sourceforge.pmd.lang.java.types.TypeSystem.wildcard(TypeSystem.java:640)
at net.sourceforge.pmd.lang.java.types.WildcardTypeImpl.subst(WildcardTypeImpl.java:36)
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:926)
at net.sourceforge.pmd.lang.java.types.TypeOps.mapPreservingSelf(TypeOps.java:953)
at net.sourceforge.pmd.lang.java.types.TypeOps.subst(TypeOps.java:926)
at net.sourceforge.pmd.lang.java.types.JClassType.subst(JClassType.java:76)
at net.sourceforge.pmd.lang.java.types.JClassType.subst(JClassType.java:52)
at net.sourceforge.pmd.lang.java.types.TypeOps.lambda$subst$0(TypeOps.java:926)
at net.sourceforge.pmd.lang.java.types.TypeOps.mapPreservingSelf(TypeOps.java:953)
at net.sourceforge.pmd.lang.java.types.TypeOps.subst(TypeOps.java:926)
at net.sourceforge.pmd.lang.java.symbols.internal.asm.ExecutableStub.getFormalParameterTypes(ExecutableStub.java:101)
at net.sourceforge.pmd.lang.java.types.ClassMethodSigImpl.getFormalParameters(ClassMethodSigImpl.java:115)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.isPotentiallyApplicable(Infer.java:973)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.computeCompileTimeDecl(Infer.java:272)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.getCompileTimeDecl(Infer.java:249)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback(Infer.java:182)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively(Infer.java:171)
at net.sourceforge.pmd.lang.java.types.ast.PolyResolution.inferInvocation(PolyResolution.java:251)
at net.sourceforge.pmd.lang.java.types.ast.PolyResolution.polyTypeOtherCtx(PolyResolution.java:123)
at net.sourceforge.pmd.lang.java.types.ast.PolyResolution.computePolyType(PolyResolution.java:113)
at net.sourceforge.pmd.lang.java.types.ast.LazyTypeResolver.handlePoly(LazyTypeResolver.java:268)
at net.sourceforge.pmd.lang.java.types.ast.LazyTypeResolver.visit(LazyTypeResolver.java:273)
at net.sourceforge.pmd.lang.java.types.ast.LazyTypeResolver.visit(LazyTypeResolver.java:95)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.acceptVisitor(ASTMethodCall.java:75)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode.getTypeMirror(AbstractJavaTypeNode.java:51)
... 22 more
The text was updated successfully, but these errors were encountered:
Affects PMD Version:7.0.0-rc4
Description:
I have encountered a crash while using generics and wildcards in the provided code snippet. The usage of these features seems to trigger an unexpected behavior, resulting in an exception when analyzed by PMD.
Code Sample demonstrating the issue:
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
pmd check -d SubClass.java -R category/java/bestpractices.xml -f text
Running PMD through: [CLI]
Exception Stacktrace:
The text was updated successfully, but these errors were encountered: