Repository navigation
Description
Affects PMD Version: 7.28.0 (and earlier)
Description:
When the analysis cache is enabled, ZipFileFingerprinter opens every jar/zip on the
auxclasspath to fingerprint it. If one of them is not a valid archive (e.g. a jar with a
broken zip64 extra field, or a non-zip file with a .jar extension), the resulting
ZipException is not handled: ZipFileFingerprinter#fingerprint only catches
FileNotFoundException/NoSuchFileException, so the exception propagates to
AbstractAnalysisCache#checkValidity, which logs
"Incremental analysis can't fingerprint classpath contents" and throws a RuntimeException.
The whole analysis is aborted.
#7102 (fix for #7101) made AuxClasspathLoader skip invalid archives with a warning, but
the fingerprinter still fails on them. Since the analysis cache is initialized first, an
invalid archive still aborts the analysis when the cache is enabled.
Reported for the IntelliJ PMD plugin, which always enables the analysis cache:
amitdev/PMD-Intellij#322
java.util.zip.ZipException: Invalid CEN header (invalid zip64 extra data field size)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:180)
at net.sourceforge.pmd.cache.internal.ZipFileFingerprinter.fingerprint(ZipFileFingerprinter.java:64)
at net.sourceforge.pmd.cache.internal.ClasspathFingerprinter.fingerprint(ClasspathFingerprinter.java:36)
at net.sourceforge.pmd.cache.internal.AbstractAnalysisCache.checkValidity(AbstractAnalysisCache.java:131)
...
at net.sourceforge.pmd.PmdAnalysis.performAnalysisAndCollectReport(PmdAnalysis.java:374)
Steps to reproduce:
echo "not a zip" > invalid.jar
echo "public class Foo { private int unused; }" > Foo.java
pmd check -d Foo.java -R category/java/bestpractices.xml/UnusedPrivateField \
--aux-classpath invalid.jar --cache pmd.cache
Output (PMD 7.28.0, Java 25):
[ERROR] Incremental analysis can't fingerprint classpath contents
java.util.zip.ZipException: zip END header not found
[ERROR] Exception while initializing analysis listeners: java.util.zip.ZipException: zip END header not found
[ERROR] Exception during processing: Exception while initializing analysis listeners
[ERROR] Exception while running PMD.: Cannot get result before listener is closed
The same command with --no-cache succeeds and reports the violation, because
AuxClasspathLoader skips the invalid archive since #7102.
Expected outcome:
Like AuxClasspathLoader since #7102: the invalid archive is skipped with a warning and
the analysis continues. When the archive later becomes valid, it should affect the
fingerprint again, so the cache gets invalidated.
Running PMD through: Other (IntelliJ plugin, PMD API); reproducible with the CLI
Activity
[core] Fix pmd#7156: Analysis cache fails with ZipException on invali…