Skip to content

Commit 91e459a

Browse files
committed
Polish "Limit ChronoField values to their range"
See gh-19595
1 parent 9bc68b9 commit 91e459a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/CentralDirectoryFileHeader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*
3131
* @author Phillip Webb
3232
* @author Andy Wilkinson
33+
* @author Dmytro Nosan
3334
* @see <a href="https://en.wikipedia.org/wiki/Zip_%28file_format%29">Zip File Format</a>
3435
*/
3536

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
import java.net.URL;
2626
import java.net.URLClassLoader;
2727
import java.nio.charset.Charset;
28+
import java.nio.file.attribute.FileTime;
29+
import java.time.Instant;
2830
import java.util.Enumeration;
2931
import java.util.jar.JarEntry;
3032
import java.util.jar.JarInputStream;
33+
import java.util.jar.JarOutputStream;
3134
import java.util.jar.Manifest;
3235
import java.util.zip.ZipEntry;
3336
import java.util.zip.ZipFile;
@@ -39,6 +42,7 @@
3942

4043
import org.springframework.boot.loader.TestJarCreator;
4144
import org.springframework.boot.loader.data.RandomAccessDataFile;
45+
import org.springframework.test.util.ReflectionTestUtils;
4246
import org.springframework.util.FileCopyUtils;
4347
import org.springframework.util.StreamUtils;
4448

@@ -54,6 +58,7 @@
5458
* @author Phillip Webb
5559
* @author Martin Lau
5660
* @author Andy Wilkinson
61+
* @author Madhura Bhave
5762
*/
5863
public class JarFileTests {
5964

@@ -493,6 +498,26 @@ public void multiReleaseEntry() throws Exception {
493498
assertThat(inputStream.read()).isEqualTo(getJavaVersion());
494499
}
495500

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+
496521
private int getJavaVersion() {
497522
try {
498523
Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);

0 commit comments

Comments
 (0)