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
This commit is contained in:
parent
b982bbec37
commit
ebebe09a9d
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -511,12 +511,13 @@ public class JarFileTests {
|
|||
jarOutputStream.write(new byte[] { (byte) 1 });
|
||||
jarOutputStream.closeEntry();
|
||||
}
|
||||
JarFile jarFile = new JarFile(file);
|
||||
Enumeration<java.util.jar.JarEntry> entries = jarFile.entries();
|
||||
try (JarFile jar = new JarFile(file)) {
|
||||
Enumeration<java.util.jar.JarEntry> entries = jar.entries();
|
||||
JarEntry entry = entries.nextElement();
|
||||
assertThat(entry.getLastModifiedTime().toInstant()).isEqualTo(Instant.EPOCH);
|
||||
assertThat(entry.getName()).isEqualTo("1.dat");
|
||||
}
|
||||
}
|
||||
|
||||
private int getJavaVersion() {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue