'maven fails to find files in main package: ZIP file can't be opened as a file system because an entry has a '.' or '..' element in its name

I have a maven project that I can no longer get to build:

mvn clean compile

ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project dise_java: Compilation failure: Compilation failure: 
[ERROR] /home/jeffemandel/springdise/dise_java/src/main/java/org/jeffmandel/springdise/CSPNonceFilter.java:[1,1] cannot access org.jeffmandel.springdise
[ERROR]   ZIP file can't be opened as a file system because an entry has a '.' or '..' element in its name

CSPNonceFilter is the first file encountered, otherwise, nothing special, but the first line is:

package org.jeffmandel.springdise;

I've updated JDK and maven to the latest versions, deleted my ~/.m2/repository and rebuilt it without success. Being desperate, I started commenting out dependencies in my POM, and found a single dependency that would cause the failure:

<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>vega</artifactId>
    <version>5.21.0</version>
</dependency>

Now I've had vega in my POM for some time, and it's a webjar, so why javac would care is beyond me. I can certainly work around this, but having killed a day on this, I want to understand. Thoughts?



Solution 1:[1]

I ran into the same issue for a Gradle project a few days ago and got it resolved. Though not all details are exactly the same, I guess you probably had the same issue with me.

TL;DR: It is probably caused by: 1) a JDK behavior change with certain zip files and, 2) certain dependency jars that are not standard formatted.


I'll explain my issue below:

  1. JDK behavior change due to a bug fix

JDK had an issue processing zip files that include certain special zip entries; '.' and '..' are such zip entries.

This JDK issue ticket https://bugs.openjdk.java.net/browse/JDK-8251329 fixed the issue by detecting such entries and throwing a ZipException. If you're interested in the code change, here's the commit (as commented in the ticket): https://github.com/openjdk/jdk/commit/3e3051e2ee93142983e9a3edee038e4f7b5ac0f2

jdk code change (partial)

Note:

This issue has also been backported to other major JDK versions like JDK 11/13/15/17/etc. so for all these major JDK versions, there is a certain minor version that included the code for such bug fix, and all minor versions after that one would have such behavior of throwing the Exception.

For my case, we first found such issue when trying to upgrade from JDK 8 to JDK 11; and this might also explain why you "can no longer get to build".

  1. Dependency jars that are not "standard"

Normally in a dependency jar such entries shouldn't exist, but things may go wrong sometimes.

For my case, it's a locally imported javawddx.jar, originally downloaded from https://sourceforge.net/projects/javawddx/ as it's not published to maven repository.

javawddx.jar zip entries

(Notice there's a '.' directory entry in the jar.)

I solved the issue by deleting the '.' directory and re-zip the jar.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1