Skip to content

Commit ebebe09

Browse files
committed
Fix file handle leak in JarFileTests
The JarFile was not being closed which linked a file handle and caused a test failure on Windows. The local variable has been renamed as, when declared in a try-with-resources, Checkstyle was confused by the shadowing of the jarFile field and required references to jarFile within the try-block the be prefixed with this. See gh-19595
1 parent b982bbe commit ebebe09

File tree

1 file changed

+7
-6
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -511,11 +511,12 @@ public void jarFileEntryWithEpochTimeOfZeroShouldNotFail() throws Exception {
511511
jarOutputStream.write(new byte[] { (byte) 1 });
512512
jarOutputStream.closeEntry();
513513
}
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");
514+
try (JarFile jar = new JarFile(file)) {
515+
Enumeration<java.util.jar.JarEntry> entries = jar.entries();
516+
JarEntry entry = entries.nextElement();
517+
assertThat(entry.getLastModifiedTime().toInstant()).isEqualTo(Instant.EPOCH);
518+
assertThat(entry.getName()).isEqualTo("1.dat");
519+
}
519520
}
520521

521522
private int getJavaVersion() {

0 commit comments

Comments
 (0)