Commit 91e459a5 authored by Madhura Bhave's avatar Madhura Bhave

Polish "Limit ChronoField values to their range"

See gh-19595
parent 9bc68b98
...@@ -30,6 +30,7 @@ import org.springframework.boot.loader.data.RandomAccessData; ...@@ -30,6 +30,7 @@ import org.springframework.boot.loader.data.RandomAccessData;
* *
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Dmytro Nosan
* @see <a href="https://en.wikipedia.org/wiki/Zip_%28file_format%29">Zip File Format</a> * @see <a href="https://en.wikipedia.org/wiki/Zip_%28file_format%29">Zip File Format</a>
*/ */
......
...@@ -25,9 +25,12 @@ import java.io.InputStream; ...@@ -25,9 +25,12 @@ import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
...@@ -39,6 +42,7 @@ import org.junit.rules.TemporaryFolder; ...@@ -39,6 +42,7 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.boot.loader.TestJarCreator; import org.springframework.boot.loader.TestJarCreator;
import org.springframework.boot.loader.data.RandomAccessDataFile; import org.springframework.boot.loader.data.RandomAccessDataFile;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
...@@ -54,6 +58,7 @@ import static org.mockito.Mockito.verify; ...@@ -54,6 +58,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb * @author Phillip Webb
* @author Martin Lau * @author Martin Lau
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Madhura Bhave
*/ */
public class JarFileTests { public class JarFileTests {
...@@ -493,6 +498,26 @@ public class JarFileTests { ...@@ -493,6 +498,26 @@ public class JarFileTests {
assertThat(inputStream.read()).isEqualTo(getJavaVersion()); assertThat(inputStream.read()).isEqualTo(getJavaVersion());
} }
@Test
public void jarFileEntryWithEpochTimeOfZeroShouldNotFail() throws Exception {
File file = this.temporaryFolder.newFile();
FileOutputStream fileOutputStream = new FileOutputStream(file);
try (JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream)) {
jarOutputStream.setComment("outer");
JarEntry entry = new JarEntry("1.dat");
entry.setLastModifiedTime(FileTime.from(Instant.EPOCH));
ReflectionTestUtils.setField(entry, "xdostime", 0);
jarOutputStream.putNextEntry(entry);
jarOutputStream.write(new byte[] { (byte) 1 });
jarOutputStream.closeEntry();
}
JarFile jarFile = new JarFile(file);
Enumeration<java.util.jar.JarEntry> entries = jarFile.entries();
JarEntry entry = entries.nextElement();
assertThat(entry.getLastModifiedTime().toInstant()).isEqualTo(Instant.EPOCH);
assertThat(entry.getName()).isEqualTo("1.dat");
}
private int getJavaVersion() { private int getJavaVersion() {
try { try {
Object runtimeVersion = Runtime.class.getMethod("version").invoke(null); Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment