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
Crash while executing rule CognitiveComplexity on constructor with Map.of().
The created Map has the following type: Map<Class, Serializer> (Serializer is a interface)
Exception Stacktrace:
[INFO] --- pmd:3.23.0:check (default-cli) @ root ---
[INFO] PMD version: 7.2.0
Warning: Exception applying rule CognitiveComplexity on file /home/runner/work/mockserver-neolight/mockserver-neolight/core/src/main/java/software/xdev/mockserver/serialization/WebSocketMessageSerializer.java, continuing with next rule
org.apache.commons.lang3.exception.ContextedRuntimeException: java.lang.IllegalArgumentException: Empty set
Exception Context:
[1:Resolving type of=!debug only! [MethodCall:40:22]Map.of(
HttpRequest.class, new HttpRequestSerializer(),
HttpResponse.class, new HttpResponseSerializer(),
HttpRequestAndHttpRespon(truncated)]
[2:Rule applied on node=!debug only! [ConstructorDeclaration:38:9]public WebSocketMessageSerializer()
{
this.serializers = Map.of(
HttpRequest.class, new HttpRequestSerializer(),
HttpResponse.clas(truncated)]
---------------------------------
at net.sourceforge.pmd.util.AssertionUtil.contexted (AssertionUtil.java:236)
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.metrics.internal.CognitiveComplexityVisitor.visit (CognitiveComplexityVisitor.java:245)
at net.sourceforge.pmd.lang.java.metrics.internal.CognitiveComplexityVisitor.visit (CognitiveComplexityVisitor.java:41)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.acceptVisitor (ASTMethodCall.java:71)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitChildren (AstVisitorBase.java:31)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitNode (AstVisitorBase.java:38)
at net.sourceforge.pmd.lang.java.ast.JavaVisitor.visitJavaNode (JavaVisitor.java:6)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visitExpression (JavaVisitorBase.java:132)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visit (JavaVisitorBase.java:142)
at net.sourceforge.pmd.lang.java.ast.ASTAssignmentExpression.acceptVisitor (ASTAssignmentExpression.java:56)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitChildren (AstVisitorBase.java:31)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitNode (AstVisitorBase.java:38)
at net.sourceforge.pmd.lang.java.ast.JavaVisitor.visitJavaNode (JavaVisitor.java:6)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visitStatement (JavaVisitorBase.java:281)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visit (JavaVisitorBase.java:321)
at net.sourceforge.pmd.lang.java.ast.ASTExpressionStatement.acceptVisitor (ASTExpressionStatement.java:27)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.java.metrics.internal.CognitiveComplexityVisitor.visit (CognitiveComplexityVisitor.java:226)
at net.sourceforge.pmd.lang.java.metrics.internal.CognitiveComplexityVisitor.visit (CognitiveComplexityVisitor.java:41)
at net.sourceforge.pmd.lang.java.ast.ASTBlock.acceptVisitor (ASTBlock.java:30)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitChildren (AstVisitorBase.java:31)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitNode (AstVisitorBase.java:38)
at net.sourceforge.pmd.lang.java.ast.JavaVisitor.visitJavaNode (JavaVisitor.java:6)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visitMethodOrCtor (JavaVisitorBase.java:33)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visit (JavaVisitorBase.java:43)
at net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration.acceptVisitor (ASTConstructorDeclaration.java:45)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.java.metrics.JavaMetrics.computeCognitive (JavaMetrics.java:469)
at net.sourceforge.pmd.lang.metrics.Metric$1.computeFor (Metric.java:154)
at net.sourceforge.pmd.lang.metrics.MetricsUtil.computeMetric (MetricsUtil.java:137)
at net.sourceforge.pmd.lang.metrics.MetricsUtil.computeMetric (MetricsUtil.java:102)
at net.sourceforge.pmd.lang.metrics.MetricsUtil.computeMetric (MetricsUtil.java:83)
at net.sourceforge.pmd.lang.java.rule.design.CognitiveComplexityRule.visitMethod (CognitiveComplexityRule.java:56)
at net.sourceforge.pmd.lang.java.rule.design.CognitiveComplexityRule.visit (CognitiveComplexityRule.java:48)
at net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration.acceptVisitor (ASTConstructorDeclaration.java:45)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply (AbstractJavaRule.java:30)
at net.sourceforge.pmd.lang.rule.RuleReference.apply (RuleReference.java:415)
at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex (RuleApplicator.java:77)
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.util.concurrent.Executors$RunnableAdapter.call (Executors.java:539)
at java.util.concurrent.FutureTask.run (FutureTask.java:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
at java.lang.Thread.run (Thread.java:840)
Caused by: java.lang.IllegalArgumentException: Empty set
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lcp (Lub.java:177)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lambda$lub$0 (Lub.java:159)
at net.sourceforge.pmd.util.CollectionUtil.map (CollectionUtil.java:426)
at net.sourceforge.pmd.util.CollectionUtil.map (CollectionUtil.java:386)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lub (Lub.java:156)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lub (Lub.java:112)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.computeLcta (Lub.java:259)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lcta (Lub.java:219)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lcp (Lub.java:203)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lcp (Lub.java:185)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lambda$lub$0 (Lub.java:159)
at net.sourceforge.pmd.util.CollectionUtil.map (CollectionUtil.java:430)
at net.sourceforge.pmd.util.CollectionUtil.map (CollectionUtil.java:386)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lub (Lub.java:156)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lub (Lub.java:112)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.computeLcta (Lub.java:259)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lcta (Lub.java:219)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lcp (Lub.java:203)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lcp (Lub.java:185)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lambda$lub$0 (Lub.java:159)
at net.sourceforge.pmd.util.CollectionUtil.map (CollectionUtil.java:426)
at net.sourceforge.pmd.util.CollectionUtil.map (CollectionUtil.java:386)
at net.sourceforge.pmd.lang.java.types.Lub$LubJudge.lub (Lub.java:156)
at net.sourceforge.pmd.lang.java.types.Lub.lub (Lub.java:36)
at net.sourceforge.pmd.lang.java.types.TypeSystem.lub (TypeSystem.java:680)
at net.sourceforge.pmd.lang.java.types.internal.infer.ReductionStep$2.solve (ReductionStep.java:41)
at net.sourceforge.pmd.lang.java.types.internal.infer.InferenceContext.solveBatchProgressed (InferenceContext.java:479)
at net.sourceforge.pmd.lang.java.types.internal.infer.InferenceContext.solve (InferenceContext.java:459)
at net.sourceforge.pmd.lang.java.types.internal.infer.InferenceContext.solve (InferenceContext.java:435)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.instantiateImpl (Infer.java:580)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.instantiateMaybeNoInfer (Infer.java:545)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.instantiateMethod (Infer.java:389)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.instantiateMethodOrCtor (Infer.java:369)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.logInference (Infer.java:352)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.computeCompileTimeDecl (Infer.java:292)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.getCompileTimeDecl (Infer.java:254)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:187)
at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:176)
at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:263)
at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:135)
at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:125)
at net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver.handlePoly (LazyTypeResolver.java:267)
at net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver.visit (LazyTypeResolver.java:272)
at net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver.visit (LazyTypeResolver.java:95)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.acceptVisitor (ASTMethodCall.java:71)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaTypeNode.getTypeMirror (AbstractJavaTypeNode.java:51)
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.metrics.internal.CognitiveComplexityVisitor.visit (CognitiveComplexityVisitor.java:245)
at net.sourceforge.pmd.lang.java.metrics.internal.CognitiveComplexityVisitor.visit (CognitiveComplexityVisitor.java:41)
at net.sourceforge.pmd.lang.java.ast.ASTMethodCall.acceptVisitor (ASTMethodCall.java:71)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitChildren (AstVisitorBase.java:31)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitNode (AstVisitorBase.java:38)
at net.sourceforge.pmd.lang.java.ast.JavaVisitor.visitJavaNode (JavaVisitor.java:6)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visitExpression (JavaVisitorBase.java:132)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visit (JavaVisitorBase.java:142)
at net.sourceforge.pmd.lang.java.ast.ASTAssignmentExpression.acceptVisitor (ASTAssignmentExpression.java:56)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitChildren (AstVisitorBase.java:31)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitNode (AstVisitorBase.java:38)
at net.sourceforge.pmd.lang.java.ast.JavaVisitor.visitJavaNode (JavaVisitor.java:6)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visitStatement (JavaVisitorBase.java:281)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visit (JavaVisitorBase.java:321)
at net.sourceforge.pmd.lang.java.ast.ASTExpressionStatement.acceptVisitor (ASTExpressionStatement.java:27)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.java.metrics.internal.CognitiveComplexityVisitor.visit (CognitiveComplexityVisitor.java:226)
at net.sourceforge.pmd.lang.java.metrics.internal.CognitiveComplexityVisitor.visit (CognitiveComplexityVisitor.java:41)
at net.sourceforge.pmd.lang.java.ast.ASTBlock.acceptVisitor (ASTBlock.java:30)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitChildren (AstVisitorBase.java:31)
at net.sourceforge.pmd.lang.ast.AstVisitorBase.visitNode (AstVisitorBase.java:38)
at net.sourceforge.pmd.lang.java.ast.JavaVisitor.visitJavaNode (JavaVisitor.java:6)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visitMethodOrCtor (JavaVisitorBase.java:33)
at net.sourceforge.pmd.lang.java.ast.JavaVisitorBase.visit (JavaVisitorBase.java:43)
at net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration.acceptVisitor (ASTConstructorDeclaration.java:45)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.java.metrics.JavaMetrics.computeCognitive (JavaMetrics.java:469)
at net.sourceforge.pmd.lang.metrics.Metric$1.computeFor (Metric.java:154)
at net.sourceforge.pmd.lang.metrics.MetricsUtil.computeMetric (MetricsUtil.java:137)
at net.sourceforge.pmd.lang.metrics.MetricsUtil.computeMetric (MetricsUtil.java:102)
at net.sourceforge.pmd.lang.metrics.MetricsUtil.computeMetric (MetricsUtil.java:83)
at net.sourceforge.pmd.lang.java.rule.design.CognitiveComplexityRule.visitMethod (CognitiveComplexityRule.java:56)
at net.sourceforge.pmd.lang.java.rule.design.CognitiveComplexityRule.visit (CognitiveComplexityRule.java:48)
at net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration.acceptVisitor (ASTConstructorDeclaration.java:45)
at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply (AbstractJavaRule.java:30)
at net.sourceforge.pmd.lang.rule.RuleReference.apply (RuleReference.java:415)
at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex (RuleApplicator.java:77)
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.util.concurrent.Executors$RunnableAdapter.call (Executors.java:539)
at java.util.concurrent.FutureTask.run (FutureTask.java:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
at java.lang.Thread.run (Thread.java:840)
Warning: Exception occurred on node !debug only! [ConstructorDeclaration:38:9]public WebSocketMessageSerializer()
{
this.serializers = Map.of(
HttpRequest.class, new HttpRequestSerializer(),
HttpResponse.clas(truncated)
Warning: There are 1 PMD processing errors:
Warning: /home/runner/work/mockserver-neolight/mockserver-neolight/core/src/main/java/software/xdev/mockserver/serialization/WebSocketMessageSerializer.java: ContextedRuntimeException: java.lang.IllegalArgumentException: Empty set
Exception Context:
[1:Resolving type of=!debug only! [MethodCall:40:22]Map.of(
HttpRequest.class, new HttpRequestSerializer(),
HttpResponse.class, new HttpResponseSerializer(),
HttpRequestAndHttpRespon(truncated)]
[2:Rule applied on node=!debug only! [ConstructorDeclaration:38:9]public WebSocketMessageSerializer()
{
this.serializers = Map.of(
HttpRequest.class, new HttpRequestSerializer(),
HttpResponse.clas(truncated)]
---------------------------------
adangel
changed the title
[Java] Crash while executing rule CognitiveComplexity on constructor with Map.of()
[java] CognitiveComplexity: Exception when using Map.of()Aug 29, 2024
Affects PMD Version:
7.2.0
Description:
Crash while executing rule
CognitiveComplexity
on constructor withMap.of()
.The created
Map
has the following type:Map<Class, Serializer>
(Serializer
is a interface)Exception Stacktrace:
Code Sample demonstrating the issue:
https://github.com/xdev-software/mockserver-neolight/blob/fe69619264fcc28c69c82ee06335f0695f274c1e/core/src/main/java/software/xdev/mockserver/serialization/WebSocketMessageSerializer.java#L36-L45
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
./mvnw compile pmd:aggregate-pmd-no-fork -P pmd
Running PMD through: [Maven]
The text was updated successfully, but these errors were encountered: