diff --git a/src/main/java/hudson/remoting/Checksum.java b/src/main/java/hudson/remoting/Checksum.java index fd6a9d164..360cf6bf6 100644 --- a/src/main/java/hudson/remoting/Checksum.java +++ b/src/main/java/hudson/remoting/Checksum.java @@ -4,6 +4,7 @@ import java.io.DataInputStream; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.security.DigestOutputStream; @@ -74,8 +75,10 @@ static Checksum forFile(File file) throws IOException { static Checksum forURL(URL url) throws IOException { try { MessageDigest md = MessageDigest.getInstance(JarLoaderImpl.DIGEST_ALGORITHM); - Util.copy(url.openStream(), new DigestOutputStream(new NullOutputStream(), md)); - return new Checksum(md.digest(), md.getDigestLength() / 8); + try(InputStream istsream = url.openStream(); OutputStream ostream = new DigestOutputStream(new NullOutputStream(), md)) { + Util.copy(istsream, ostream); + return new Checksum(md.digest(), md.getDigestLength() / 8); + } } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); }