Merge branch '2.1.x' into 2.2.x
Closes gh-19713
This commit is contained in:
@@ -28,6 +28,8 @@ import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
@@ -47,6 +49,7 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.data.RandomAccessDataFile;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
@@ -62,6 +65,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
* @author Martin Lau
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@ExtendWith(JarUrlProtocolHandler.class)
|
||||
class JarFileTests {
|
||||
@@ -578,6 +582,26 @@ class JarFileTests {
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
|
||||
@Test
|
||||
void jarFileEntryWithEpochTimeOfZeroShouldNotFail() throws Exception {
|
||||
File file = new File(this.tempDir, "timed.jar");
|
||||
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() {
|
||||
try {
|
||||
Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);
|
||||
|
||||
Reference in New Issue
Block a user