codehaus-plexus / plexus-archiver

https://codehaus-plexus.github.io/plexus-archiver/
Apache License 2.0
44 stars 48 forks source link

Unpacking jared source code fails on unix time negative value #354

Closed spacetom closed 2 weeks ago

spacetom commented 2 weeks ago

When unpacking source code using maven-dependency-plugin the action fails for some libraries. The issue happens when there are files containing entries with last modified time before initial value of unix time (1970-01-01T00:00). When such time is turned into unix time it gets negative value and later on when the value is passed to File.setLastModified() the method throws IllegalArgumentException("Negative time"). The issue happens for library version 4.10.0 AbstractUnArchiver class at line 328. Exemplary library containing such entries is /net/minidev/json-smart/2.5.1/json-smart-2.5.1-sources.jar.

Possible fix might be:

            long time = entryDate.getTime();
            if (time < 0) {
                getLogger().warn("File {} contains entry {} with negative last modified time {}" +
                    " Replacing it with 0.", srcF.getPath(), entryName, time);
                time = 0;
            }
            targetFileName.setLastModified(time);
spacetom commented 2 weeks ago

Duplicate of https://github.com/codehaus-plexus/plexus-archiver/issues/170