From 244b5391bce46880ae0055214a21e1725ab944da Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 14 Jan 2020 17:20:29 +0000 Subject: [PATCH] Fix file handle leak in JarFileArchiveTests Closes gh-19655 --- .../boot/loader/archive/JarFileArchiveTests.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java index 41801217a1..8cec7bb0dd 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/archive/JarFileArchiveTests.java @@ -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. @@ -174,11 +174,12 @@ class JarFileArchiveTests { } try (JarFile jarFile = new JarFile(file)) { ZipEntry nestedEntry = jarFile.getEntry("nested/zip64.jar"); - JarFile nestedJarFile = jarFile.getNestedJarFile(nestedEntry); - Iterator iterator = nestedJarFile.iterator(); - for (int i = 0; i < 65537; i++) { - assertThat(iterator.hasNext()).as(i + "nth file is present").isTrue(); - iterator.next(); + try (JarFile nestedJarFile = jarFile.getNestedJarFile(nestedEntry)) { + Iterator iterator = nestedJarFile.iterator(); + for (int i = 0; i < 65537; i++) { + assertThat(iterator.hasNext()).as(i + "nth file is present").isTrue(); + iterator.next(); + } } } }