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] Parsing failed in ParseLock#doParse() java.io.IOException: Stream closed #4899

Closed
mkolesnikov opened this issue Mar 27, 2024 · 1 comment · Fixed by #4949
Closed
Assignees
Labels
a:bug PMD crashes or fails to analyse a file.
Milestone

Comments

@mkolesnikov
Copy link

mkolesnikov commented Mar 27, 2024

Affects PMD Version:

PMD 7.0.0

Description:

Running maven build in multi-threaded mode -T

Exception Stacktrace:

[ERROR] Parsing failed in ParseLock#doParse()
java.io.IOException: Stream closed
    at java.util.zip.InflaterInputStream.ensureOpen (InflaterInputStream.java:68)
    at java.util.zip.InflaterInputStream.read (InflaterInputStream.java:154)
    at java.io.FilterInputStream.read (FilterInputStream.java:119)
    at org.objectweb.asm.ClassReader.readStream (ClassReader.java:323)
    at org.objectweb.asm.ClassReader.<init> (ClassReader.java:288)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.ClassStub$1.doParse (ClassStub.java:95)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.ParseLock.getFinalStatus (ParseLock.java:33)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.ParseLock.isFailed (ParseLock.java:66)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.ClassStub.isUnresolved (ClassStub.java:487)
    at net.sourceforge.pmd.lang.java.types.ClassTypeImpl.checkUserEnclosingTypeIsOk (ClassTypeImpl.java:452)
    at net.sourceforge.pmd.lang.java.types.ClassTypeImpl.validateParams (ClassTypeImpl.java:418)
    at net.sourceforge.pmd.lang.java.types.ClassTypeImpl.<init> (ClassTypeImpl.java:69)
    at net.sourceforge.pmd.lang.java.types.ClassTypeImpl.<init> (ClassTypeImpl.java:64)
    at net.sourceforge.pmd.lang.java.types.TypeSystem.parameterise (TypeSystem.java:522)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeSigParser$TypeScanner.makeClassType (TypeSigParser.java:364)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeSigParser.classType (TypeSigParser.java:164)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeSigParser.typeSignature (TypeSigParser.java:148)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeSigParser.methodType (TypeSigParser.java:53)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.SignatureParser.parseMethodType (SignatureParser.java:65)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase$LazyMethodType.doParse (GenericSigBase.java:245)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase$1.doParse (GenericSigBase.java:54)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.ParseLock.getFinalStatus (ParseLock.java:33)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.ParseLock.ensureParsed (ParseLock.java:22)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase.ensureParsed (GenericSigBase.java:76)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase.getTypeParams (GenericSigBase.java:92)
    at net.sourceforge.pmd.lang.java.symbols.internal.asm.ExecutableStub.getTypeParameters (ExecutableStub.java:60)
    at net.sourceforge.pmd.lang.java.types.ClassMethodSigImpl.getTypeParameters (ClassMethodSigImpl.java:127)
    at net.sourceforge.pmd.lang.java.types.JMethodSig.isGeneric (JMethodSig.java:161)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.isPotentiallyApplicable (Infer.java:985)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.computeCompileTimeDecl (Infer.java:273)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.getCompileTimeDecl (Infer.java:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:67)
    at net.sourceforge.pmd.lang.java.types.internal.infer.ast.MethodInvocMirror.getAccessibleCandidates (MethodInvocMirror.java:27)
    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:250)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.goToInvocationWithFallback (Infer.java:183)
    at net.sourceforge.pmd.lang.java.types.internal.infer.Infer.inferInvocationRecursively (Infer.java:172)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.inferInvocation (PolyResolution.java:254)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.polyTypeOtherCtx (PolyResolution.java:126)
    at net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution.computePolyType (PolyResolution.java:116)
    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:75)
    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.InternalApiBridge.lambda$forceTypeResolutionPhase$0 (InternalApiBridge.java:86)
    at java.util.Iterator.forEachRemaining (Iterator.java:133)
    at net.sourceforge.pmd.lang.ast.internal.IteratorBasedNStream.forEach (IteratorBasedNStream.java:102)
    at net.sourceforge.pmd.lang.java.ast.InternalApiBridge.forceTypeResolutionPhase (InternalApiBridge.java:84)
    at net.sourceforge.pmd.lang.java.internal.JavaAstProcessor.lambda$process$3 (JavaAstProcessor.java:134)
    at net.sourceforge.pmd.benchmark.TimeTracker.bench (TimeTracker.java:163)
    at net.sourceforge.pmd.lang.java.internal.JavaAstProcessor.process (JavaAstProcessor.java:134)
    at net.sourceforge.pmd.lang.java.internal.JavaAstProcessor.process (JavaAstProcessor.java:164)
    at net.sourceforge.pmd.lang.java.internal.JavaAstProcessor.process (JavaAstProcessor.java:148)
    at net.sourceforge.pmd.lang.java.ast.JavaParser.parseImpl (JavaParser.java:69)
    at net.sourceforge.pmd.lang.java.ast.JavaParser.parseImpl (JavaParser.java:25)
    at net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter.parse (JjtreeParserAdapter.java:36)
    at net.sourceforge.pmd.lang.impl.PmdRunnable.parse (PmdRunnable.java:112)
    at net.sourceforge.pmd.lang.impl.PmdRunnable.processSource (PmdRunnable.java:132)
    at net.sourceforge.pmd.lang.impl.PmdRunnable.run (PmdRunnable.java:80)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:572)
    at java.util.concurrent.FutureTask.run (FutureTask.java:317)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
    at java.lang.Thread.run (Thread.java:1583)

Code Sample demonstrating the issue:

With current implementation the doParse() can be called only once, so canReenter should return false or classReader should be shared or InputStream.reset() should be called.

           // note to devs: to debug the parsing logic you might have
            // to replace the implementation of toString temporarily,
            // otherwise an IDE could call toString just to show the item
            // in the debugger view (which could cause parsing of the class file).

            @Override
            protected boolean doParse() throws IOException {
                try (InputStream instream = loader.getInputStream()) {
                    if (instream != null) {
                        ClassReader classReader = new ClassReader(instream);
                        ClassStubBuilder builder = new ClassStubBuilder(ClassStub.this, resolver);
                        classReader.accept(builder, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
                        return true;
                    } else {
                        return false;
                    }
                }
            }

            @Override
            protected boolean canReenter() {
                // We might call the parsing logic again in the same thread,
                // e.g. in order to determine "annotAttributes", getDeclaredMethods() is called, which
                // calls ensureParsed().
                // Note: Other threads can't reenter, since our thread own the ParseLock monitor.
                return true;
            }

Steps to reproduce:

Use maven multi-module project with lots of modules

mvn clean verify -T 2

jdk21
maven 3.9.6
maven-pmd-plugin 3.21.2

@mkolesnikov mkolesnikov added the a:bug PMD crashes or fails to analyse a file. label Mar 27, 2024
@adangel adangel changed the title [java] PDM 7.0.0: [ERROR] Parsing failed in ParseLock#doParse() java.io.IOException: Stream closed [java] Parsing failed in ParseLock#doParse() java.io.IOException: Stream closed Mar 28, 2024
@jsotuyod jsotuyod added the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Apr 2, 2024
@adangel adangel self-assigned this Apr 9, 2024
@adangel adangel added this to the 7.1.0 milestone Apr 9, 2024
@adangel adangel removed the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Apr 11, 2024
@adangel
Copy link
Member

adangel commented Apr 11, 2024

Luckily, this was reproducible with pmd itself, by just running ./mvnw -T4 pmd:pmd in the PMD repository.

It turns out, that we run into a Java optimization: Opened Jar Files are cached and there is only one instance in the running JVM for each physically existing JarFile. Our ClasspathClassLoader is extending URLClassLoader for loading the bytecode class-files from the auxiliary classpath via getResourceAsStream. URLClassLoader will keep track of any opened JarFiles and will close them when itself is closed. Running maven in multithreaded mode means, that multiple modules of the project run in parallel. These modules often share the same dependencies, so it's very likely that the auxclasspath for some modules contain the same jar files. Since the JarFiles are cached within the JVM (the impl is in sun.net.www.protocol.jar.JarURLConnection and the actual cache in sun.net.www.protocol.jar.JarFileFactory), the ClasspathClassLoader of PMD in one maven module might close the JarFile of another maven module - leading to the Stream Closed exceptions.

Here's a reproducer of the issue (it uses .m2/repository/net/sourceforge/pmd/pmd-core/7.0.0/pmd-core-7.0.0.jar from your local maven repo):

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Semaphore;

class Scratch {
    static Path jarFilePath = Path.of(System.getProperty("user.home"), ".m2/repository/net/sourceforge/pmd/pmd-core/7.0.0/pmd-core-7.0.0.jar");

    private static class MyClassLoader extends URLClassLoader {
        public MyClassLoader(URL[] urls, ClassLoader parent) {
            super(urls, parent);
        }

        @Override
        public void close() throws IOException {
            super.close();
            System.out.println(Thread.currentThread().getName() + ": Closed MyClassLoader");
        }
    }

    private static class MyThread implements Runnable {
        private final int number;
        private final CyclicBarrier waitForDone;
        private final Semaphore grapResource;

        public MyThread(int number, CyclicBarrier waitForDone, Semaphore grapResource) {
            this.number = number;
            this.waitForDone = waitForDone;
            this.grapResource = grapResource;
        }

        private void log(String message) {
            System.out.println("%s: %s".formatted(Thread.currentThread().getName(), message));
        }

        @Override
        public void run() {
            try {
                URL jarFileUrl = jarFilePath.toUri().toURL();
                String pmdVersionResourcePath = "net/sourceforge/pmd/PMDVersion.class";
                try (URLClassLoader loader = new MyClassLoader(new URL[]{jarFileUrl}, null)) {
                    InputStream stream;
                    // make sure, each threads gets the resource one after another, so that the underlying JarFile
                    // is definitely cached (if caching is enabled)
                    grapResource.acquire();
                    try {
                        stream = loader.getResourceAsStream(pmdVersionResourcePath);
                        if (stream == null) {
                            throw new RuntimeException("resource not found: " + pmdVersionResourcePath);
                        }
                    } finally {
                        grapResource.release();
                    }

                    // wait for the first thread to finish and close its URLClassLoader
                    if (number != 0) {
                        waitForDone.await();
                    }
                    byte[] bytes;
                    try (InputStream in = stream; ByteArrayOutputStream out = new ByteArrayOutputStream()) {
                        log("Reading now...");
                        in.transferTo(out);
                        bytes = out.toByteArray();
                    }
                    if (bytes.length != 2935) {
                        throw new IllegalStateException("Read error");
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                if (number == 0) {
                    // we are the first thread. Signal the other waiting threads so that
                    // they can continue. They should see now closed streams.
                    try {
                        waitForDone.await();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    } catch (BrokenBarrierException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
    
    public static void main(String[] args) throws InterruptedException, IOException {
        System.out.println("Scratch");

        // Disable caching...
        //jarFilePath.toUri().toURL().openConnection().setDefaultUseCaches(false);

        int numberOfThreads = 2;
        CyclicBarrier waitForDone = new CyclicBarrier(numberOfThreads);
        Semaphore grabResource = new Semaphore(1);

        List<Thread> threads = new ArrayList<>(numberOfThreads);
        for (int i = 0; i < numberOfThreads; i++) {
            threads.add(new Thread(new MyThread(i, waitForDone, grabResource), "Thread" + i));
        }
        threads.forEach(Thread::start);
        for (Thread thread : threads) {
            thread.join();
        }
    }
}

This gives the following output:

Scratch
Thread0: Reading now...
Thread0: Closed MyClassLoader
Thread1: Reading now...
Thread1: Closed MyClassLoader
Exception in thread "Thread1" java.lang.RuntimeException: java.io.IOException: Stream closed
	at Scratch$MyThread.run(scratch_22.java:79)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.io.IOException: Stream closed
	at java.base/java.util.zip.InflaterInputStream.ensureOpen(InflaterInputStream.java:68)
	at java.base/java.util.zip.InflaterInputStream.read(InflaterInputStream.java:154)
	at java.base/java.io.FilterInputStream.read(FilterInputStream.java:119)
	at java.base/java.io.InputStream.transferTo(InputStream.java:796)
	at Scratch$MyThread.run(scratch_22.java:71)
	... 1 more

The caching can be disabled globally by calling URLConnection#setDefaultUseCaches(false).

I'm working on solution...

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.

3 participants