Skip to content

[java] ZipException when auxClasspath contains a non-jar file (since 7.27.0) #7101

Closed

Description

@franczakr

Affects PMD Version: 7.27.0 (regression: works with 7.26.0)

Description:

Since 7.27.0, PMD aborts the whole analysis with java.util.zip.ZipException: zip END header not found when the auxclasspath contains a regular file that is not a zip/jar archive. With 7.26.0 such entries were ignored and analysis completed normally.

The new AuxClasspathLoader seems to treat every classpath entry that is not a directory as a jar and open it with JarFile. The ZipException is wrapped in an UncheckedIOException and propagates out of TypeSystem initialisation, so no file is analysed at all.

A common real-world trigger is DynamoDB Local: it depends on the com.almworks.sqlite4java native libraries (libsqlite4java-linux-amd64-1.0.392.so, sqlite4java-win32-x64-1.0.392.dll, libsqlite4java-osx-1.0.392.dylib, …) as regular artifacts. They end up on the test runtime classpath, and the Gradle PMD plugin passes them to PMD as auxclasspath entries.

Expected behaviour: classpath entries that are not valid archives are skipped (perhaps with a warning), as in 7.26.0, rather than failing the run.

Exception Stacktrace:

Execution failed for task ':pmdMain' (registered by plugin 'org.gradle.pmd').
> A failure occurred while executing org.gradle.api.plugins.quality.internal.PmdInvoker
   > java.io.UncheckedIOException: java.util.zip.ZipException: zip END header not found

Caused by: java.io.UncheckedIOException: java.util.zip.ZipException: zip END header not found
	at net.sourceforge.pmd.util.AuxClasspathLoader.lambda$openJarFile$3(AuxClasspathLoader.java:465)
	at net.sourceforge.pmd.util.AuxClasspathLoader.openJarFile(AuxClasspathLoader.java:461)
	at net.sourceforge.pmd.util.AuxClasspathLoader.findResource(AuxClasspathLoader.java:408)
	at net.sourceforge.pmd.lang.java.internal.JavaLanguageProcessor.lambda$initTypeSystem$0(JavaLanguageProcessor.java:86)
	at net.sourceforge.pmd.lang.java.symbols.internal.asm.AsmSymbolResolver.getStreamOfInternalName(AsmSymbolResolver.java:119)
	at net.sourceforge.pmd.lang.java.symbols.internal.asm.AsmSymbolResolver.lambda$resolveClassFromBinaryName$0(AsmSymbolResolver.java:62)
	at net.sourceforge.pmd.lang.java.symbols.internal.asm.AsmSymbolResolver.resolveClassFromBinaryName(AsmSymbolResolver.java:61)
	at net.sourceforge.pmd.lang.java.types.TypeSystem.getBootStrapSymbol(TypeSystem.java:318)
	at net.sourceforge.pmd.lang.java.types.TypeSystem.createPrimitive(TypeSystem.java:323)
	at net.sourceforge.pmd.lang.java.types.TypeSystem.<init>(TypeSystem.java:226)
	at net.sourceforge.pmd.lang.java.types.TypeSystem.usingClasspath(TypeSystem.java:203)
	at net.sourceforge.pmd.lang.java.internal.JavaLanguageProcessor.initTypeSystem(JavaLanguageProcessor.java:86)
	at net.sourceforge.pmd.lang.java.internal.JavaLanguageProcessor.<init>(JavaLanguageProcessor.java:59)
	at net.sourceforge.pmd.lang.java.JavaLanguageModule.createProcessor(JavaLanguageModule.java:68)
	at net.sourceforge.pmd.lang.LanguageProcessorRegistry.create(LanguageProcessorRegistry.java:143)
	at net.sourceforge.pmd.lang.LanguageProcessorRegistry.create(LanguageProcessorRegistry.java:120)
	at net.sourceforge.pmd.PmdAnalysis.performAnalysisImpl(PmdAnalysis.java:431)
	at net.sourceforge.pmd.PmdAnalysis.performAnalysisImpl(PmdAnalysis.java:388)
	at net.sourceforge.pmd.PmdAnalysis.performAnalysis(PmdAnalysis.java:368)
	at net.sourceforge.pmd.ant.internal.PMDTaskImpl.doTask(PMDTaskImpl.java:144)
	at net.sourceforge.pmd.ant.internal.PMDTaskImpl.execute(PMDTaskImpl.java:248)
	at net.sourceforge.pmd.ant.PMDTask.execute(PMDTask.java:79)
	... 38 more
Caused by: java.util.zip.ZipException: zip END header not found
	at net.sourceforge.pmd.util.AuxClasspathLoader.lambda$openJarFile$3(AuxClasspathLoader.java:463)
	... 59 more

Code Sample demonstrating the issue:

The source code doesn't matter: any file fails, because the crash happens while the type system is being initialised. For example:

package demo;

public final class Hello {
    private Hello() {
    }

    public static String greet(String name) {
        return "Hello " + name;
    }
}

Steps to reproduce:

  1. Create a minimal Gradle project with the class above in src/main/java/demo/Hello.java and these build files:

    settings.gradle.kts

    rootProject.name = "pmd-repro"

    build.gradle.kts

    plugins {
        java
        pmd
    }
    
    repositories { mavenCentral() }
    
    dependencies {
        // Any regular file on the classpath that is not a zip/jar, e.g. a native library
        implementation(files("libs/libnative.so"))
    }
    
    pmd {
        toolVersion = providers.gradleProperty("pmdVersion").getOrElse("7.27.0")
        ruleSets = listOf("category/java/bestpractices.xml")
    }
  2. Add a dummy file that isn't a zip: mkdir libs && printf '\x7fELF not a zip file' > libs/libnative.so

  3. ./gradlew pmdMain -PpmdVersion=7.26.0 → BUILD SUCCESSFUL

  4. ./gradlew pmdMain -PpmdVersion=7.27.0 → fails with the stack trace above

Workaround: filter out classpath entries that aren't archives in the PMD task:

tasks.withType<Pmd>().configureEach {
    classpath = classpath?.filter { it.isDirectory || it.name.endsWith(".jar") }
}

Running PMD through: Gradle

Gradle 9.7.1, JDK 25, macOS 26.7 aarch64. Also reproduced on Linux (GitLab CI).

Activity

  1. added
    a:bug
    on Sep 23, 2026
  2. added this to the 7.28.0 milestone on Sep 24, 2026
  3. adangel commented on Sep 24, 2026

    @adangel
    Member

    Thanks for reporting!

    While it doesn't make sense, to put native libs on the classpath, I agree, that PMD should skip them. The URLClassLoader we used previously skipped them as well.

  4. changed the title [-][java] 7.27.0: ZipException "zip END header not found" when auxclasspath contains a non-jar file[/-] [+][java] ZipException "zip END header not found" when auxclasspath contains a non-jar file (since 7.27.0)[/+] on Sep 24, 2026
  5. changed the title [-][java] ZipException "zip END header not found" when auxclasspath contains a non-jar file (since 7.27.0)[/-] [+][java] ZipException "zip END header not found" when auxClasspath contains a non-jar file (since 7.27.0)[/+] on Sep 24, 2026
  6. added a commit that references this issue on Sep 24, 2026
    56251a2
  7. changed the title [-][java] ZipException "zip END header not found" when auxClasspath contains a non-jar file (since 7.27.0)[/-] [+][java] ZipException when auxClasspath contains a non-jar file (since 7.27.0)[/+] on Sep 24, 2026
  8. added a commit that references this issue on Sep 25, 2026
    388f07a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions