|
25 | 25 | import java.net.URL;
|
26 | 26 | import java.net.URLClassLoader;
|
27 | 27 | import java.nio.charset.Charset;
|
| 28 | +import java.nio.file.attribute.FileTime; |
| 29 | +import java.time.Instant; |
28 | 30 | import java.util.Enumeration;
|
29 | 31 | import java.util.jar.JarEntry;
|
30 | 32 | import java.util.jar.JarInputStream;
|
| 33 | +import java.util.jar.JarOutputStream; |
31 | 34 | import java.util.jar.Manifest;
|
32 | 35 | import java.util.zip.ZipEntry;
|
33 | 36 | import java.util.zip.ZipFile;
|
|
39 | 42 |
|
40 | 43 | import org.springframework.boot.loader.TestJarCreator;
|
41 | 44 | import org.springframework.boot.loader.data.RandomAccessDataFile;
|
| 45 | +import org.springframework.test.util.ReflectionTestUtils; |
42 | 46 | import org.springframework.util.FileCopyUtils;
|
43 | 47 | import org.springframework.util.StreamUtils;
|
44 | 48 |
|
|
54 | 58 | * @author Phillip Webb
|
55 | 59 | * @author Martin Lau
|
56 | 60 | * @author Andy Wilkinson
|
| 61 | + * @author Madhura Bhave |
57 | 62 | */
|
58 | 63 | public class JarFileTests {
|
59 | 64 |
|
@@ -493,6 +498,26 @@ public void multiReleaseEntry() throws Exception {
|
493 | 498 | assertThat(inputStream.read()).isEqualTo(getJavaVersion());
|
494 | 499 | }
|
495 | 500 |
|
| 501 | + @Test |
| 502 | + public void jarFileEntryWithEpochTimeOfZeroShouldNotFail() throws Exception { |
| 503 | + File file = this.temporaryFolder.newFile(); |
| 504 | + FileOutputStream fileOutputStream = new FileOutputStream(file); |
| 505 | + try (JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream)) { |
| 506 | + jarOutputStream.setComment("outer"); |
| 507 | + JarEntry entry = new JarEntry("1.dat"); |
| 508 | + entry.setLastModifiedTime(FileTime.from(Instant.EPOCH)); |
| 509 | + ReflectionTestUtils.setField(entry, "xdostime", 0); |
| 510 | + jarOutputStream.putNextEntry(entry); |
| 511 | + jarOutputStream.write(new byte[] { (byte) 1 }); |
| 512 | + jarOutputStream.closeEntry(); |
| 513 | + } |
| 514 | + JarFile jarFile = new JarFile(file); |
| 515 | + Enumeration<java.util.jar.JarEntry> entries = jarFile.entries(); |
| 516 | + JarEntry entry = entries.nextElement(); |
| 517 | + assertThat(entry.getLastModifiedTime().toInstant()).isEqualTo(Instant.EPOCH); |
| 518 | + assertThat(entry.getName()).isEqualTo("1.dat"); |
| 519 | + } |
| 520 | + |
496 | 521 | private int getJavaVersion() {
|
497 | 522 | try {
|
498 | 523 | Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);
|
|
0 commit comments