Mercurial > hg > release > icedtea7-2.6
view patches/boot/ecj-trywithresources.patch @ 3027:55366d981edf icedtea-2.6.24
Bump to 2.6.24.
Upstream changes:
- JDK-8145096: Undefined behaviour in HotSpot
- JDK-8215265: C2: range check elimination may allow illegal out of bound access
- JDK-8233624: Enhance JNI linkage
- JDK-8236862: Enhance support of Proxy class
- JDK-8237990: Enhanced LDAP contexts
- JDK-8237995: Enhance certificate processing
- JDK-8240124: Better VM Interning
- JDK-8241114: Better range handling
- JDK-8242680: Improved URI Support
- JDK-8242685: Better Path Validation
- JDK-8242695: Enhanced buffer support
- JDK-8243302: Advanced class supports
- JDK-8244136: Improved Buffer supports
- JDK-8244479: Further constrain certificates
- JDK-8244955: Additional Fix for JDK-8240124
- JDK-8245407: Enhance zoning of times
- JDK-8245412: Better class definitions
- JDK-8245417: Improve certificate chain handling
- JDK-8248574: Improve jpeg processing
- JDK-8249927: Specify limits of jdk.serialProxyInterfaceLimit
- JDK-8250861, PR3812: Crash in MinINode::Ideal(PhaseGVN*, bool)
- JDK-8253019: Enhanced JPEG decoding
ChangeLog:
2020-11-04 Andrew John Hughes <gnu_andrew@member.fsf.org>
Bump to 2.6.24.
* Makefile.am:
(CORBA_CHANGESET): Update to icedtea-2.6.24.
(JAXP_CHANGESET): Likewise.
(JAXWS_CHANGESET): Likewise.
(JDK_CHANGESET): Likewise.
(LANGTOOLS_CHANGESET): Likewise.
(OPENJDK_CHANGESET): Likewise.
(CORBA_SHA256SUM): Likewise.
(JAXP_SHA256SUM): Likewise.
(JAXWS_SHA256SUM): Likewise.
(JDK_SHA256SUM): Likewise.
(LANGTOOLS_SHA256SUM): Likewise.
(OPENJDK_SHA256SUM): Likewise.
* NEWS: Updated.
* acinclude.m4:
(JDK_UPDATE_VERSION): Bump to 281.
* configure.ac: Bump to 2.6.24.
* hotspot.map.in: Update to icedtea-2.6.24.
* patches/boot/ecj-diamond.patch:
Regenerated. Add new case in
com.sun.jndi.ldap.LdapCtx.
* patches/boot/ecj-multicatch.patch:
Add new case in sun.nio.fs.UnixUriUtils.
* patches/boot/ecj-trywithresources.patch:
Regenerated due to changed context in
sun.security.util.UntrustedCertificates.
author | Andrew John Hughes <gnu_andrew@member.fsf.org> |
---|---|
date | Thu, 05 Nov 2020 06:56:23 +0000 |
parents | 9c3802d62131 |
children |
line wrap: on
line source
diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/crypto/provider/SealedObjectForKeyProtector.java openjdk-boot/jdk/src/share/classes/com/sun/crypto/provider/SealedObjectForKeyProtector.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/crypto/provider/SealedObjectForKeyProtector.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/crypto/provider/SealedObjectForKeyProtector.java 2020-11-03 06:06:00.676884676 +0000 @@ -77,16 +77,10 @@ throws IOException, ClassNotFoundException, IllegalBlockSizeException, BadPaddingException { - try (ObjectInputStream ois = SharedSecrets.getJavaxCryptoSealedObjectAccess() - .getExtObjectInputStream(this, c)) { - AccessController.doPrivileged(new PrivilegedAction<Void>() { - @Override - public Void run() { - ObjectInputFilter.Config.setObjectInputFilter(ois, - new DeserializationChecker(maxLength)); - return null; - } - }); + ObjectInputStream ois = null; + try { + ois = SharedSecrets.getJavaxCryptoSealedObjectAccess().getExtObjectInputStream(this, c); + AccessController.doPrivileged(new FilterSetter(ois, maxLength)); try { @SuppressWarnings("unchecked") Key t = (Key) ois.readObject(); @@ -101,6 +95,25 @@ throw ice; } } + } finally { + if (ois != null) { + ois.close(); + } + } + } + + private static class FilterSetter implements PrivilegedAction<Void> { + private final ObjectInputStream ois; + private final int maxLength; + public FilterSetter(ObjectInputStream ois, int maxLength) { + this.ois = ois; + this.maxLength = maxLength; + } + @Override + public Void run() { + ObjectInputFilter.Config.setObjectInputFilter(ois, + new DeserializationChecker(maxLength)); + return null; } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/BandStructure.java 2020-11-03 06:06:00.718884114 +0000 @@ -743,7 +743,9 @@ private void dumpBand() throws IOException { assert(optDumpBands); - try (PrintStream ps = new PrintStream(getDumpStream(this, ".txt"))) { + PrintStream ps = null; + try { + ps = new PrintStream(getDumpStream(this, ".txt")); String irr = (bandCoding == regularCoding) ? "" : " irregular"; ps.print("# length="+length+ " size="+outputSize()+ @@ -758,9 +760,19 @@ } printArrayTo(ps, values, 0, length); } - try (OutputStream ds = getDumpStream(this, ".bnd")) { + finally { + if (ps != null) + ps.close(); + } + OutputStream ds = null; + try { + ds = getDumpStream(this, ".bnd"); bandCoding.writeArrayTo(ds, values, 0, length); } + finally { + if (ds != null) + ds.close(); + } } /** Disburse one value. */ @@ -829,12 +841,18 @@ private void dumpBand() throws IOException { assert(optDumpBands); - try (OutputStream ds = getDumpStream(this, ".bnd")) { + OutputStream ds = null; + try { + ds = getDumpStream(this, ".bnd"); if (bytesForDump != null) bytesForDump.writeTo(ds); else bytes.writeTo(ds); } + finally { + if (ds != null) + ds.close(); + } } public void readDataFrom(InputStream in) throws IOException { diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java 2020-11-02 03:16:28.941280513 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java 2020-11-03 06:06:00.721884138 +0000 @@ -151,8 +151,13 @@ if ("--config-file=".equals(state)) { String propFile = av.remove(0); Properties fileProps = new Properties(); - try (InputStream propIn = new FileInputStream(propFile)) { + InputStream propIn = null; + try { + propIn = new FileInputStream(propFile); fileProps.load(propIn); + } finally { + if (propIn != null) + propIn.close(); } if (engProps.get(verboseProp) != null) fileProps.list(System.out); @@ -343,9 +348,14 @@ else fileOut = new FileOutputStream(outfile); fileOut = new BufferedOutputStream(fileOut); - try (JarOutputStream out = new JarOutputStream(fileOut)) { + JarOutputStream out = null; + try { + out = new JarOutputStream(fileOut); junpack.unpack(in, out); // p200 closes in but not out + } finally { + if (out != null) + out.close(); } // At this point, we have a good jarfile (or newfile, if -r) } @@ -407,7 +417,9 @@ long filelen = new File(jarfile).length(); if (filelen <= 0) return ""; long skiplen = Math.max(0, filelen - tail.length); - try (InputStream in = new FileInputStream(new File(jarfile))) { + InputStream in = null; + try { + in = new FileInputStream(new File(jarfile)); in.skip(skiplen); in.read(tail); for (int i = tail.length-4; i >= 0; i--) { @@ -421,6 +433,9 @@ } } return ""; + } finally { + if (in != null) + in.close(); } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/NativeUnpack.java 2020-11-03 06:06:00.723884130 +0000 @@ -245,9 +245,15 @@ void run(File inFile, JarOutputStream jstream) throws IOException { // %%% maybe memory-map the file, and pass it straight into unpacker ByteBuffer mappedFile = null; - try (FileInputStream fis = new FileInputStream(inFile)) { + FileInputStream fis = null; + try { + fis = new FileInputStream(inFile); run(fis, jstream, mappedFile); } + finally { + if (fis != null) + fis.close(); + } // Note: caller is responsible to finish with jstream. } diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java 2020-11-03 06:06:00.724884125 +0000 @@ -540,9 +540,15 @@ Index index = initCPIndex(tag, cpMap); if (optDumpBands) { - try (PrintStream ps = new PrintStream(getDumpStream(index, ".idx"))) { + PrintStream ps = null; + try { + ps = new PrintStream(getDumpStream(index, ".idx")); printArrayTo(ps, index.cpMap, 0, index.cpMap.length); } + finally { + if (ps != null) + ps.close(); + } } } @@ -828,9 +834,10 @@ attr_definition_headers.readFrom(in); attr_definition_name.readFrom(in); attr_definition_layout.readFrom(in); - try (PrintStream dump = !optDumpBands ? null - : new PrintStream(getDumpStream(attr_definition_headers, ".def"))) - { + PrintStream dump = null; + try { + dump = !optDumpBands ? null + : new PrintStream(getDumpStream(attr_definition_headers, ".def")); for (int i = 0; i < numAttrDefs; i++) { int header = attr_definition_headers.getByte(); Utf8Entry name = (Utf8Entry) attr_definition_name.getRef(); @@ -849,6 +856,10 @@ if (dump != null) dump.println(index+" "+def); } } + finally { + if (dump != null) + dump.close(); + } attr_definition_headers.doneDisbursing(); attr_definition_name.doneDisbursing(); attr_definition_layout.doneDisbursing(); diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java 2020-11-03 06:06:00.726884116 +0000 @@ -458,9 +458,15 @@ Utils.log.info("Writing "+cpMap.length+" "+ConstantPool.tagName(tag)+" entries..."); if (optDumpBands) { - try (PrintStream ps = new PrintStream(getDumpStream(index, ".idx"))) { + PrintStream ps = null; + try { + ps = new PrintStream(getDumpStream(index, ".idx")); printArrayTo(ps, cpMap, 0, cpMap.length); } + finally { + if (ps != null) + ps.close(); + } } switch (tag) { @@ -921,9 +927,10 @@ } }); attrDefsWritten = new Attribute.Layout[numAttrDefs]; - try (PrintStream dump = !optDumpBands ? null - : new PrintStream(getDumpStream(attr_definition_headers, ".def"))) - { + PrintStream dump = null; + try { + dump = !optDumpBands ? null + : new PrintStream(getDumpStream(attr_definition_headers, ".def")); int[] indexForDebug = Arrays.copyOf(attrIndexLimit, ATTR_CONTEXT_LIMIT); for (int i = 0; i < defs.length; i++) { int header = ((Integer)defs[i][0]).intValue(); @@ -949,6 +956,10 @@ } } } + finally { + if (dump != null) + dump.close(); + } } void writeAttrCounts() throws IOException { diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/PropMap.java openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/PropMap.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/PropMap.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/PropMap.java 2020-11-03 06:06:00.726884116 +0000 @@ -122,8 +122,9 @@ // Do this after the previous props are put in place, // to allow override if necessary. String propFile = "intrinsic.properties"; - - try (InputStream propStr = PackerImpl.class.getResourceAsStream(propFile)) { + InputStream propStr = null; + try { + propStr = PackerImpl.class.getResourceAsStream(propFile); if (propStr == null) { throw new RuntimeException(propFile + " cannot be loaded"); } @@ -131,6 +132,14 @@ } catch (IOException ee) { throw new RuntimeException(ee); } + finally { + try { + if (propStr != null) + propStr.close(); + } catch (IOException ee) { + throw new RuntimeException(ee); + } + } for (Map.Entry<Object, Object> e : props.entrySet()) { String key = (String) e.getKey(); diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java 2020-11-03 06:06:00.726884116 +0000 @@ -160,9 +160,15 @@ } // Use the stream-based implementation. // %%% Reconsider if native unpacker learns to memory-map the file. - try (FileInputStream instr = new FileInputStream(in)) { + FileInputStream instr = null; + try { + instr = new FileInputStream(in); unpack(instr, out); } + finally { + if (instr != null) + instr.close(); + } if (props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) { in.delete(); } diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/Utils.java openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/Utils.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/java/util/jar/pack/Utils.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/java/util/jar/pack/Utils.java 2020-11-03 06:06:00.727884117 +0000 @@ -268,18 +268,30 @@ // 4947205 : Peformance is slow when using pack-effort=0 out = new BufferedOutputStream(out); out = new NonCloser(out); // protect from JarOutputStream.close() - try (JarOutputStream jout = new JarOutputStream(out)) { + JarOutputStream jout = null; + try { + jout = new JarOutputStream(out); copyJarFile(in, jout); } + finally { + if (jout != null) + jout.close(); + } } static void copyJarFile(JarFile in, OutputStream out) throws IOException { // 4947205 : Peformance is slow when using pack-effort=0 out = new BufferedOutputStream(out); out = new NonCloser(out); // protect from JarOutputStream.close() - try (JarOutputStream jout = new JarOutputStream(out)) { + JarOutputStream jout = null; + try { + jout = new JarOutputStream(out); copyJarFile(in, jout); } + finally { + if (jout != null) + jout.close(); + } } // Wrapper to prevent closing of client-supplied stream. static private diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/jndi/dns/DnsClient.java openjdk-boot/jdk/src/share/classes/com/sun/jndi/dns/DnsClient.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/jndi/dns/DnsClient.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/jndi/dns/DnsClient.java 2020-11-03 06:06:00.727884117 +0000 @@ -399,7 +399,9 @@ int minTimeout = 50; // msec after which there are no retries. synchronized (udpSocketLock) { - try (DatagramSocket udpSocket = getDatagramSocket()) { + DatagramSocket udpSocket = null; + try { + udpSocket = getDatagramSocket(); DatagramPacket opkt = new DatagramPacket( pkt.getData(), pkt.length(), server, port); DatagramPacket ipkt = new DatagramPacket(new byte[8000], 8000); @@ -436,6 +438,8 @@ udpSocket.disconnect(); } return null; // no matching packet received within the timeout + } finally { + if (udpSocket != null) { udpSocket.close(); } } } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/jndi/dns/DNSDatagramSocketFactory.java openjdk-boot/jdk/src/share/classes/com/sun/jndi/dns/DNSDatagramSocketFactory.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/jndi/dns/DNSDatagramSocketFactory.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/jndi/dns/DNSDatagramSocketFactory.java 2020-11-03 06:06:00.727884117 +0000 @@ -199,6 +199,10 @@ SocketException e = new SocketException(x.getMessage()); e.initCause(x); throw e; + } catch (Throwable x) { + SocketException e = new SocketException(x.getMessage()); + e.initCause(x); + throw e; } } return new DatagramSocket(); @@ -238,6 +242,8 @@ return new DatagramSocket(port); } catch (IOException x) { // try again until maxtries == 0; + } catch (Throwable x) { + // try again until maxtries == 0; } } return null; diff -Nru openjdk-boot.orig/jdk/src/share/classes/com/sun/jndi/ldap/Obj.java openjdk-boot/jdk/src/share/classes/com/sun/jndi/ldap/Obj.java --- openjdk-boot.orig/jdk/src/share/classes/com/sun/jndi/ldap/Obj.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/com/sun/jndi/ldap/Obj.java 2020-11-03 06:06:00.727884117 +0000 @@ -503,9 +503,13 @@ try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - try (ObjectOutputStream serial = new ObjectOutputStream(bytes)) { + ObjectOutputStream serial = null; + try { + serial = new ObjectOutputStream(bytes); serial.writeObject(obj); - } + } finally { + if (serial != null) { serial.close(); } + } return (bytes.toByteArray()); @@ -525,15 +529,19 @@ try { // Create ObjectInputStream for deserialization ByteArrayInputStream bytes = new ByteArrayInputStream(obj); - try (ObjectInputStream deserial = cl == null ? + ObjectInputStream deserial = null; + try { + deserial = cl == null ? new ObjectInputStream(bytes) : - new LoaderInputStream(bytes, cl)) { + new LoaderInputStream(bytes, cl); return deserial.readObject(); } catch (ClassNotFoundException e) { NamingException ne = new NamingException(); ne.setRootCause(e); throw ne; - } + } finally { + if (deserial != null) { deserial.close(); } + } } catch (IOException e) { NamingException ne = new NamingException(); ne.setRootCause(e); diff -Nru openjdk-boot.orig/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java openjdk-boot/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java --- openjdk-boot.orig/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java 2020-11-03 06:06:00.728884122 +0000 @@ -912,10 +912,15 @@ java.net.URLConnection uconn = tClass.getResource(tResource).openConnection(); int len = uconn.getContentLength(); byte[] bytes = new byte[len]; - try (java.io.InputStream str = uconn.getInputStream()) { + java.io.InputStream str = null; + try { + str = uconn.getInputStream(); int nr = str.read(bytes); if (nr != len) throw new java.io.IOException(tResource); - } + } finally { + if (str != null) + str.close(); + } values[0] = bytes; } catch (java.io.IOException ex) { throw newInternalError(ex); diff -Nru openjdk-boot.orig/jdk/src/share/classes/java/lang/Package.java openjdk-boot/jdk/src/share/classes/java/lang/Package.java --- openjdk-boot.orig/jdk/src/share/classes/java/lang/Package.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/java/lang/Package.java 2020-11-03 06:06:00.728884122 +0000 @@ -578,12 +578,23 @@ * Returns the Manifest for the specified JAR file name. */ private static Manifest loadManifest(String fn) { - try (FileInputStream fis = new FileInputStream(fn); - JarInputStream jis = new JarInputStream(fis, false)) - { + FileInputStream fis = null; + JarInputStream jis = null; + try { + fis = new FileInputStream(fn); + jis = new JarInputStream(fis, false); return jis.getManifest(); } catch (IOException e) { return null; + } finally { + try { + if (jis != null) + jis.close(); + if (fis != null) + fis.close(); + } catch (IOException e) { + return null; + } } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/java/nio/channels/SocketChannel.java openjdk-boot/jdk/src/share/classes/java/nio/channels/SocketChannel.java --- openjdk-boot.orig/jdk/src/share/classes/java/nio/channels/SocketChannel.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/java/nio/channels/SocketChannel.java 2020-11-03 06:06:00.728884122 +0000 @@ -188,7 +188,7 @@ } catch (Throwable suppressed) { x.addSuppressed(suppressed); } - throw x; + throw (IOException) x; } assert sc.isConnected(); return sc; diff -Nru openjdk-boot.orig/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java openjdk-boot/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java --- openjdk-boot.orig/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java 2020-11-03 06:06:00.729884127 +0000 @@ -122,9 +122,15 @@ if (attrs.isDirectory()) { Files.createDirectory(target); } else { - try (InputStream in = Files.newInputStream(source)) { + InputStream in = null; + try { + in = Files.newInputStream(source); Files.copy(in, target); } + finally { + if (in != null) + in.close(); + } } // copy basic attributes to target @@ -142,7 +148,7 @@ } catch (Throwable suppressed) { x.addSuppressed(suppressed); } - throw x; + throw (IOException) x; } } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/java/nio/file/Files.java openjdk-boot/jdk/src/share/classes/java/nio/file/Files.java --- openjdk-boot.orig/jdk/src/share/classes/java/nio/file/Files.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/java/nio/file/Files.java 2020-11-03 06:06:00.729884127 +0000 @@ -2604,7 +2604,9 @@ * Create a FileTreeWalker to walk the file tree, invoking the visitor * for each event. */ - try (FileTreeWalker walker = new FileTreeWalker(options, maxDepth)) { + FileTreeWalker walker = null; + try { + walker = new FileTreeWalker(options, maxDepth); FileTreeWalker.Event ev = walker.walk(start); do { FileVisitResult result; @@ -2651,6 +2653,8 @@ } ev = walker.next(); } while (ev != null); + } finally { + if (walker != null) { walker.close(); } } return start; @@ -2903,8 +2907,11 @@ } // do the copy - try (OutputStream out = ostream) { - return copy(in, out); + try { + return copy(in, ostream); + } + finally { + ostream.close(); } } @@ -2945,9 +2952,15 @@ // ensure not null before opening file Objects.requireNonNull(out); - try (InputStream in = newInputStream(source)) { + InputStream in = null; + try { + in = newInputStream(source); return copy(in, out); } + finally { + if (in != null) + in.close(); + } } /** @@ -3031,14 +3044,27 @@ * method is invoked to check read access to the file. */ public static byte[] readAllBytes(Path path) throws IOException { - try (SeekableByteChannel sbc = Files.newByteChannel(path); - InputStream in = Channels.newInputStream(sbc)) { + SeekableByteChannel sbc = null; + InputStream in = null; + + try { + sbc = Files.newByteChannel(path); + in = Channels.newInputStream(sbc); long size = sbc.size(); if (size > (long)MAX_BUFFER_SIZE) throw new OutOfMemoryError("Required array size too large"); return read(in, (int)size); - } + } finally { + IOException e = null; + + if (in != null) + try { in.close(); } catch (IOException ex) { e = ex; } + if (sbc != null) + try { sbc.close(); } catch (IOException ex) { e = ex; } + + if (e != null) throw e; + } } /** @@ -3083,7 +3109,9 @@ public static List<String> readAllLines(Path path, Charset cs) throws IOException { - try (BufferedReader reader = newBufferedReader(path, cs)) { + BufferedReader reader = null; + try { + reader = newBufferedReader(path, cs); List<String> result = new ArrayList<>(); for (;;) { String line = reader.readLine(); @@ -3093,6 +3121,10 @@ } return result; } + finally { + if (reader != null) + reader.close(); + } } /** @@ -3142,7 +3174,9 @@ // ensure bytes is not null before opening file Objects.requireNonNull(bytes); - try (OutputStream out = Files.newOutputStream(path, options)) { + OutputStream out = null; + try { + out = Files.newOutputStream(path, options); int len = bytes.length; int rem = len; while (rem > 0) { @@ -3151,6 +3185,10 @@ rem -= n; } } + finally { + if (out != null) + out.close(); + } return path; } @@ -3201,12 +3239,20 @@ // ensure lines is not null before opening file Objects.requireNonNull(lines); CharsetEncoder encoder = cs.newEncoder(); - try (OutputStream out = newOutputStream(path, options); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, encoder))) { + OutputStream out = null; + BufferedWriter writer = null; + try { + out = newOutputStream(path, options); + writer = new BufferedWriter(new OutputStreamWriter(out, encoder)); for (CharSequence line: lines) { writer.append(line); writer.newLine(); } + } finally { + if (writer != null) + writer.close(); + if (out != null) + out.close(); } return path; } diff -Nru openjdk-boot.orig/jdk/src/share/classes/java/util/Currency.java openjdk-boot/jdk/src/share/classes/java/util/Currency.java --- openjdk-boot.orig/jdk/src/share/classes/java/util/Currency.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/java/util/Currency.java 2020-11-03 06:06:00.730884128 +0000 @@ -241,8 +241,12 @@ File propFile = new File(propsFile); if (propFile.exists()) { Properties props = new Properties(); - try (FileReader fr = new FileReader(propFile)) { + FileReader fr = null; + try { + fr = new FileReader(propFile); props.load(fr); + } finally { + fr.close(); } Set<String> keys = props.stringPropertyNames(); Pattern propertiesPattern = diff -Nru openjdk-boot.orig/jdk/src/share/classes/java/util/jar/JarFile.java openjdk-boot/jdk/src/share/classes/java/util/jar/JarFile.java --- openjdk-boot.orig/jdk/src/share/classes/java/util/jar/JarFile.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/java/util/jar/JarFile.java 2020-11-03 06:06:00.730884128 +0000 @@ -386,13 +386,18 @@ * META-INF files. */ private byte[] getBytes(ZipEntry ze) throws IOException { - try (InputStream is = super.getInputStream(ze)) { + InputStream is = null; + try { + is = super.getInputStream(ze); int len = (int)ze.getSize(); byte[] b = IOUtils.readAllBytes(is); if (len != -1 && b.length != len) throw new EOFException("Expected:" + len + ", read:" + b.length); return b; + } finally { + if (is != null) + is.close(); } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/javax/sql/rowset/serial/SerialClob.java openjdk-boot/jdk/src/share/classes/javax/sql/rowset/serial/SerialClob.java --- openjdk-boot.orig/jdk/src/share/classes/javax/sql/rowset/serial/SerialClob.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/javax/sql/rowset/serial/SerialClob.java 2020-11-03 06:06:00.730884128 +0000 @@ -144,8 +144,9 @@ buf = new char[(int)len]; int read = 0; int offset = 0; - - try (Reader charStream = clob.getCharacterStream()) { + Reader charStream = null; + try { + charStream = clob.getCharacterStream(); if (charStream == null) { throw new SQLException("Invalid Clob object. The call to getCharacterStream " + "returned null which cannot be serialized."); @@ -153,23 +154,41 @@ // Note: get an ASCII stream in order to null-check it, // even though we don't do anything with it. - try (InputStream asciiStream = clob.getAsciiStream()) { + InputStream asciiStream = null; + try { + asciiStream = clob.getAsciiStream(); if (asciiStream == null) { throw new SQLException("Invalid Clob object. The call to getAsciiStream " + "returned null which cannot be serialized."); } } - - try (Reader reader = new BufferedReader(charStream)) { + finally { + if (asciiStream != null) + asciiStream.close(); + } + Reader reader = null; + try { + reader = new BufferedReader(charStream); do { read = reader.read(buf, offset, (int)(len - offset)); offset += read; } while (read > 0); } + finally { + if (reader != null) + reader.close(); + } } catch (java.io.IOException ex) { throw new SerialException("SerialClob: " + ex.getMessage()); } - + finally { + try { + if (charStream != null) + charStream.close(); + } catch (java.io.IOException ex) { + throw new SerialException("SerialClob: " + ex.getMessage()); + } + } origLen = len; } diff -Nru openjdk-boot.orig/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java openjdk-boot/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java --- openjdk-boot.orig/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/javax/sql/rowset/spi/SyncFactory.java 2020-11-03 06:06:00.731884126 +0000 @@ -382,9 +382,15 @@ // Load user's implementation of SyncProvider // here. -Drowset.properties=/abc/def/pqr.txt ROWSET_PROPERTIES = strRowsetProperties; - try (FileInputStream fis = new FileInputStream(ROWSET_PROPERTIES)) { + FileInputStream fis = null; + try { + fis = new FileInputStream(ROWSET_PROPERTIES); properties.load(fis); } + finally { + if (fis != null) + fis.close(); + } parseProperties(properties); } @@ -401,17 +407,20 @@ AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws SyncFactoryException, IOException, FileNotFoundException { - try (InputStream stream = (cl == null) ? - ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES) - : cl.getResourceAsStream(ROWSET_PROPERTIES)) { - if (stream == null) { - throw new SyncFactoryException("Resource " + ROWSET_PROPERTIES + " not found"); - } - properties.load(stream); - } - return null; - } - + InputStream stream = null; + try { + stream = + (cl == null) ? ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES) + : cl.getResourceAsStream(ROWSET_PROPERTIES); + if (stream == null) { + throw new SyncFactoryException("Resource " + ROWSET_PROPERTIES + " not found"); + } + properties.load(stream); + } finally { + if (stream != null) + stream.close(); + } + return null; } }); } catch (PrivilegedActionException ex) { Throwable e = ex.getException(); diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/awt/SunToolkit.java openjdk-boot/jdk/src/share/classes/sun/awt/SunToolkit.java --- openjdk-boot.orig/jdk/src/share/classes/sun/awt/SunToolkit.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/awt/SunToolkit.java 2020-11-03 06:06:00.731884126 +0000 @@ -899,10 +899,16 @@ protected static boolean imageExists(URL url) { checkPermissions(url); if (url != null) { - try (InputStream is = url.openStream()) { + InputStream is = null; + try { + is = url.openStream(); return true; }catch(IOException e){ return false; + } finally { + if (is != null) { + try { is.close(); } catch (IOException ex) {} + } } } return false; diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/launcher/LauncherHelper.java openjdk-boot/jdk/src/share/classes/sun/launcher/LauncherHelper.java --- openjdk-boot.orig/jdk/src/share/classes/sun/launcher/LauncherHelper.java 2020-11-02 03:16:28.981280558 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/launcher/LauncherHelper.java 2020-11-03 06:06:00.731884126 +0000 @@ -555,8 +555,9 @@ if (parent == null) { parent = new File("."); } - try (DirectoryStream<Path> dstream = - Files.newDirectoryStream(parent.toPath(), glob)) { + DirectoryStream<Path> dstream = null; + try { + dstream = Files.newDirectoryStream(parent.toPath(), glob); int entries = 0; for (Path p : dstream) { out.add(p.normalize().toString()); @@ -571,6 +572,9 @@ System.err.println("Warning: passing argument as-is " + a); System.err.print(e); } + } finally { + if (dstream != null) + try { dstream.close(); } catch (IOException e) {} } } else { out.add(a.arg); diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java openjdk-boot/jdk/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java --- openjdk-boot.orig/jdk/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java 2020-11-03 06:06:00.732884123 +0000 @@ -260,8 +260,14 @@ if (fname == null) { return p; } - try (FileInputStream fin = new FileInputStream(fname)) { + FileInputStream fin = null; + try { + fin = new FileInputStream(fname); p.load(fin); + } finally { + if (fin != null) { + try { fin.close(); } catch (IOException ex) {} + } } return p; } @@ -656,9 +662,15 @@ try { // Load the SSL keystore properties from the config file Properties p = new Properties(); - try (InputStream in = new FileInputStream(sslConfigFileName)) { + InputStream in = null; + try { + in = new FileInputStream(sslConfigFileName); BufferedInputStream bin = new BufferedInputStream(in); p.load(bin); + } finally { + if (in != null) { + try { in.close(); } catch (IOException ex) {} + } } String keyStore = p.getProperty("javax.net.ssl.keyStore"); @@ -682,8 +694,14 @@ KeyStore ks = null; if (keyStore != null) { ks = KeyStore.getInstance(KeyStore.getDefaultType()); - try (FileInputStream ksfis = new FileInputStream(keyStore)) { + FileInputStream ksfis = null; + try { + ksfis = new FileInputStream(keyStore); ks.load(ksfis, keyStorePasswd); + } finally { + if (ksfis != null) { + try { ksfis.close(); } catch (IOException ex) {} + } } } KeyManagerFactory kmf = KeyManagerFactory.getInstance( @@ -693,8 +711,14 @@ KeyStore ts = null; if (trustStore != null) { ts = KeyStore.getInstance(KeyStore.getDefaultType()); - try (FileInputStream tsfis = new FileInputStream(trustStore)) { + FileInputStream tsfis = null; + try { + tsfis = new FileInputStream(trustStore); ts.load(tsfis, trustStorePasswd); + } finally { + if (tsfis != null) { + try { tsfis.close(); } catch (IOException ex) {} + } } } TrustManagerFactory tmf = TrustManagerFactory.getInstance( diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java openjdk-boot/jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java --- openjdk-boot.orig/jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java 2020-11-03 06:06:00.732884123 +0000 @@ -194,7 +194,8 @@ * Given a URL, retrieves a JAR file, caches it to disk, and creates a * cached JAR file object. */ - private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) throws IOException { + private static JarFile retrieve(final URL url, final URLJarFileCloseController closeController) + throws IOException { /* * See if interface is set, then call retrieve function of the class * that implements URLJarFileCallBack interface (sun.plugin - to @@ -211,7 +212,8 @@ JarFile result = null; /* get the stream before asserting privileges */ - try (final InputStream in = url.openConnection().getInputStream()) { + try { + final InputStream in = url.openConnection().getInputStream(); result = AccessController.doPrivileged( new PrivilegedExceptionAction<JarFile>() { public JarFile run() throws IOException { @@ -227,7 +229,10 @@ } catch (IOException ioe) { thr.addSuppressed(ioe); } - throw thr; + throw (IOException) thr; + } finally { + if (in != null) + in.close(); } } }); diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/nio/fs/PollingWatchService.java openjdk-boot/jdk/src/share/classes/sun/nio/fs/PollingWatchService.java --- openjdk-boot.orig/jdk/src/share/classes/sun/nio/fs/PollingWatchService.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/nio/fs/PollingWatchService.java 2020-11-03 06:06:00.732884123 +0000 @@ -255,7 +255,9 @@ this.entries = new HashMap<Path,CacheEntry>(); // get the initial entries in the directory - try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { + DirectoryStream<Path> stream = null; + try { + stream = Files.newDirectoryStream(dir); for (Path entry: stream) { // don't follow links long lastModified = @@ -264,6 +266,10 @@ } } catch (DirectoryIteratorException e) { throw e.getCause(); + } finally { + if (stream != null) { + stream.close(); + } } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/print/PSPrinterJob.java openjdk-boot/jdk/src/share/classes/sun/print/PSPrinterJob.java --- openjdk-boot.orig/jdk/src/share/classes/sun/print/PSPrinterJob.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/print/PSPrinterJob.java 2020-11-03 06:06:00.733884121 +0000 @@ -680,25 +680,38 @@ private void handleProcessFailure(final Process failedProcess, final String[] execCmd, final int result) throws IOException { - try (StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw)) { + StringWriter sw = null; + PrintWriter pw = null; + try { + sw = new StringWriter(); + pw = new PrintWriter(sw); pw.append("error=").append(Integer.toString(result)); pw.append(" running:"); for (String arg: execCmd) { pw.append(" '").append(arg).append("'"); } - try (InputStream is = failedProcess.getErrorStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr)) { + InputStream is = null; + InputStreamReader isr = null; + BufferedReader br = null; + try { + is = failedProcess.getErrorStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); while (br.ready()) { pw.println(); pw.append("\t\t").append(br.readLine()); } } finally { pw.flush(); + if (br != null) br.close(); + if (isr != null) isr.close(); + if (is != null) is.close(); throw new IOException(sw.toString()); } - } + } finally { + if (pw != null) pw.close(); + if (sw != null) sw.close(); + } } public Object run() { diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/reflect/misc/MethodUtil.java openjdk-boot/jdk/src/share/classes/sun/reflect/misc/MethodUtil.java --- openjdk-boot.orig/jdk/src/share/classes/sun/reflect/misc/MethodUtil.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/reflect/misc/MethodUtil.java 2020-11-03 06:06:00.733884121 +0000 @@ -383,11 +383,15 @@ } } int len = uc.getContentLength(); - try (InputStream in = new BufferedInputStream(uc.getInputStream())) { + InputStream in = null; + try { + in = new BufferedInputStream(uc.getInputStream()); byte[] b = IOUtils.readAllBytes(in); if (len != -1 && b.length != len) throw new EOFException("Expected:" + len + ", read:" + b.length); return b; + } finally { + if (in != null) { in.close(); } } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/rmi/log/ReliableLog.java openjdk-boot/jdk/src/share/classes/sun/rmi/log/ReliableLog.java --- openjdk-boot.orig/jdk/src/share/classes/sun/rmi/log/ReliableLog.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/rmi/log/ReliableLog.java 2020-11-03 06:06:00.733884121 +0000 @@ -594,10 +594,16 @@ } else { name = versionFile; } - try (FileOutputStream fos = new FileOutputStream(fName(name)); - DataOutputStream out = new DataOutputStream(fos)) { + FileOutputStream fos = null; + DataOutputStream out = null; + try { + fos = new FileOutputStream(fName(name)); + out = new DataOutputStream(fos); writeInt(out, version); - } + } finally { + if (out != null) out.close(); + if (fos != null) fos.close(); + } } /** @@ -628,10 +634,13 @@ * @exception IOException If an I/O error has occurred. */ private int readVersion(String name) throws IOException { - try (DataInputStream in = new DataInputStream - (new FileInputStream(name))) { + DataInputStream in = null; + try { + in = new DataInputStream(new FileInputStream(name)); return in.readInt(); - } + } finally { + if (in != null) in.close(); + } } /** diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/rmi/server/Activation.java openjdk-boot/jdk/src/share/classes/sun/rmi/server/Activation.java --- openjdk-boot.orig/jdk/src/share/classes/sun/rmi/server/Activation.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/rmi/server/Activation.java 2020-11-03 06:06:00.734884118 +0000 @@ -1272,13 +1272,16 @@ PipeWriter.plugTogetherPair (child.getInputStream(), System.out, child.getErrorStream(), System.err); - try (MarshalOutputStream out = - new MarshalOutputStream(child.getOutputStream())) { + MarshalOutputStream out = null; + try { + out = new MarshalOutputStream(child.getOutputStream()); out.writeObject(id); out.writeObject(desc); out.writeLong(incarnation); out.flush(); - } + } finally { + if (out != null) out.close(); + } } catch (IOException e) { diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java openjdk-boot/jdk/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java --- openjdk-boot.orig/jdk/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java 2020-11-02 03:16:29.513281118 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java 2020-11-03 06:06:00.734884118 +0000 @@ -234,13 +234,14 @@ proxyLog.log(Log.BRIEF, "trying with factory: " + factory); } - try (Socket testSocket = - factory.createSocket(host, port)) { + Socket testSocket = null; + try { // For HTTP connections, the output (POST request) must // be sent before we verify a successful connection. // So, sacrifice a socket for the sake of testing... // The following sequence should verify a successful // HTTP connection if no IOException is thrown. + testSocket = factory.createSocket(host, port); InputStream in = testSocket.getInputStream(); int b = in.read(); // probably -1 for EOF... } catch (IOException ex) { @@ -250,6 +251,10 @@ continue; } + finally { + if (testSocket != null) + testSocket.close(); + } proxyLog.log(Log.BRIEF, "factory succeeded"); // factory succeeded, open new socket for caller's use diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/Config.java openjdk-boot/jdk/src/share/classes/sun/security/krb5/Config.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/Config.java 2020-11-02 03:16:28.983280558 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/krb5/Config.java 2020-11-03 06:06:00.735884117 +0000 @@ -582,15 +582,16 @@ throws IOException, KrbException { try { List<String> v = new ArrayList<>(); - try (BufferedReader br = new BufferedReader(new InputStreamReader( - AccessController.doPrivileged( - new PrivilegedExceptionAction<FileInputStream> () { - public FileInputStream run() throws IOException { - return new FileInputStream(fileName); - } - })))) { + BufferedReader br = null; + try { String line; String previous = null; + br = new BufferedReader(new InputStreamReader(AccessController.doPrivileged( + new PrivilegedExceptionAction<FileInputStream> () { + public FileInputStream run() throws IOException { + return new FileInputStream(fileName); + } + }))); while ((line = br.readLine()) != null) { line = line.trim(); if (line.startsWith("#") || line.isEmpty()) { @@ -653,6 +654,8 @@ v.add(previous); v.add("}"); } + } finally { + if (br != null) { br.close(); } } return v; } catch (java.security.PrivilegedActionException pe) { diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java openjdk-boot/jdk/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java 2020-11-03 06:06:00.735884117 +0000 @@ -156,18 +156,33 @@ synchronized void init(PrincipalName principal, String name) throws IOException, KrbException { primaryPrincipal = principal; - try (FileOutputStream fos = new FileOutputStream(name); - CCacheOutputStream cos = new CCacheOutputStream(fos)) { + FileOutputStream fos = null; + CCacheOutputStream cos = null; + try { + fos = new FileOutputStream(name); + cos = new CCacheOutputStream(fos); version = KRB5_FCC_FVNO_3; cos.writeHeader(primaryPrincipal, version); + } finally { + try { + if (cos != null) + cos.close(); + } finally { + if (fos != null) + fos.close(); + } } + load(name); } synchronized void load(String name) throws IOException, KrbException { PrincipalName p; - try (FileInputStream fis = new FileInputStream(name); - CCacheInputStream cis = new CCacheInputStream(fis)) { + FileInputStream fis = null; + CCacheInputStream cis = null; + try { + fis = new FileInputStream(name); + cis = new CCacheInputStream(fis); version = cis.readVersion(); if (version == KRB5_FCC_FVNO_4) { tag = cis.readTag(); @@ -192,6 +207,14 @@ credentialsList.addElement(cred); } } + } finally { + try { + if (cis != null) + cis.close(); + } finally { + if (fis != null) + fis.close(); + } } } @@ -251,8 +274,11 @@ * Saves the credentials cache file to the disk. */ public synchronized void save() throws IOException, Asn1Exception { - try (FileOutputStream fos = new FileOutputStream(cacheName); - CCacheOutputStream cos = new CCacheOutputStream(fos)) { + FileOutputStream fos = null; + CCacheOutputStream cos = null; + try { + fos = new FileOutputStream(cacheName); + cos = new CCacheOutputStream(fos); cos.writeHeader(primaryPrincipal, version); Credentials[] tmp = null; if ((tmp = getCredsList()) != null) { @@ -260,6 +286,14 @@ cos.addCreds(tmp[i]); } } + } finally { + try { + if (cos != null) + cos.close(); + } finally { + if (fos != null) + fos.close(); + } } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java openjdk-boot/jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java 2020-11-03 06:06:00.735884117 +0000 @@ -92,9 +92,13 @@ tabName = filename; try { lastModified = new File(tabName).lastModified(); - try (KeyTabInputStream kis = - new KeyTabInputStream(new FileInputStream(filename))) { + KeyTabInputStream kis = null; + try { + kis = new KeyTabInputStream(new FileInputStream(filename)); load(kis); + } finally { + if (kis != null) + kis.close(); } } catch (FileNotFoundException e) { entries.clear(); @@ -417,9 +421,13 @@ public synchronized static KeyTab create(String name) throws IOException, RealmException { - try (KeyTabOutputStream kos = - new KeyTabOutputStream(new FileOutputStream(name))) { + KeyTabOutputStream kos = null; + try { + kos = new KeyTabOutputStream(new FileOutputStream(name)); kos.writeVersion(KRB5_KT_VNO); + } finally { + if (kos != null) + kos.close(); } return new KeyTab(name); } @@ -428,12 +436,16 @@ * Saves the file at the directory. */ public synchronized void save() throws IOException { - try (KeyTabOutputStream kos = - new KeyTabOutputStream(new FileOutputStream(tabName))) { + KeyTabOutputStream kos = null; + try { + kos = new KeyTabOutputStream(new FileOutputStream(tabName)); kos.writeVersion(kt_vno); for (int i = 0; i < entries.size(); i++) { kos.writeEntry(entries.elementAt(i)); } + } finally { + if (kos != null) + kos.close(); } } @@ -497,9 +509,13 @@ * @exception IOException. */ public synchronized void createVersion(File file) throws IOException { - try (KeyTabOutputStream kos = - new KeyTabOutputStream(new FileOutputStream(file))) { + KeyTabOutputStream kos = null; + try { + kos = new KeyTabOutputStream(new FileOutputStream(file)); kos.write16(KRB5_KT_VNO); + } finally { + if (kos != null) + kos.close(); } } } diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java openjdk-boot/jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java 2020-11-03 06:06:00.736884119 +0000 @@ -188,7 +188,9 @@ throws IOException, KrbApErrException { Path p = getFileName(source, time.server); int missed = 0; - try (Storage s = new Storage()) { + Storage s = null; + try { + s = new Storage(); try { missed = s.loadAndCheck(p, time, currTime); } catch (IOException ioe) { @@ -197,6 +199,8 @@ missed = s.loadAndCheck(p, time, currTime); } s.append(time); + } finally { + if (s != null) { s.close(); } } if (missed > EXCESSREPS) { Storage.expunge(p, currTime); @@ -208,8 +212,12 @@ // Static methods @SuppressWarnings("try") private static void create(Path p) throws IOException { - try (SeekableByteChannel newChan = createNoClose(p)) { + SeekableByteChannel newChan = null; + try { + newChan = createNoClose(p); // Do nothing, wait for close + } finally { + if (newChan != null) { newChan.close(); } } makeMine(p); } @@ -244,8 +252,11 @@ private static void expunge(Path p, KerberosTime currTime) throws IOException { Path p2 = Files.createTempFile(p.getParent(), "rcache", null); - try (SeekableByteChannel oldChan = Files.newByteChannel(p); - SeekableByteChannel newChan = createNoClose(p2)) { + SeekableByteChannel oldChan = null; + SeekableByteChannel newChan = null; + try { + oldChan = Files.newByteChannel(p); + newChan = createNoClose(p2); long timeLimit = currTime.getSeconds() - readHeader(oldChan); while (true) { try { @@ -258,6 +269,9 @@ break; } } + } finally { + if (newChan != null) { newChan.close(); } + if (oldChan != null) { oldChan.close(); } } makeMine(p2); Files.move(p2, p, diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/KdcComm.java openjdk-boot/jdk/src/share/classes/sun/security/krb5/KdcComm.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/krb5/KdcComm.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/krb5/KdcComm.java 2020-11-03 06:06:00.736884119 +0000 @@ -370,8 +370,9 @@ for (int i=1; i <= retries; i++) { String proto = useTCP?"TCP":"UDP"; - try (NetClient kdcClient = NetClient.getInstance( - proto, kdc, port, timeout)) { + NetClient kdcClient = null; + try { + kdcClient = NetClient.getInstance(proto, kdc, port, timeout); if (DEBUG) { System.out.println(">>> KDCCommunication: kdc=" + kdc + " " + proto + ":" @@ -400,6 +401,8 @@ throw se; } } + } finally { + if (kdcClient != null) { kdcClient.close(); } } } return ibuf; @@ -540,4 +543,3 @@ } } } - diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java openjdk-boot/jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java 2020-11-02 03:16:29.525281130 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/provider/certpath/URICertStore.java 2020-11-03 06:06:00.736884119 +0000 @@ -280,7 +280,9 @@ connection.setIfModifiedSince(lastModified); } long oldLastModified = lastModified; - try (InputStream in = connection.getInputStream()) { + InputStream in = null; + try { + in = connection.getInputStream(); lastModified = connection.getLastModified(); if (oldLastModified != 0) { if (oldLastModified == lastModified) { @@ -306,7 +308,9 @@ // Safe cast since factory is an X.509 certificate factory certs = (Collection<X509Certificate>) factory.generateCertificates(in); - } + } finally { + if (in != null) try { in.close(); } catch (IOException e) {} + } return getMatchingCerts(certs, selector); } catch (IOException e) { if (debug != null) { @@ -399,7 +403,9 @@ } long oldLastModified = lastModified; connection.setConnectTimeout(CRL_CONNECT_TIMEOUT); - try (InputStream in = connection.getInputStream()) { + InputStream in = null; + try { + in = connection.getInputStream(); lastModified = connection.getLastModified(); if (oldLastModified != 0) { if (oldLastModified == lastModified) { @@ -423,7 +429,9 @@ debug.println("Downloading new CRL..."); } crl = (X509CRL) factory.generateCRL(in); - } + } finally { + if (in != null) { try { in.close (); } catch (IOException e) {} } + } return getMatchingCRLs(crl, selector); } catch (IOException e) { if (debug != null) { diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/provider/SeedGenerator.java openjdk-boot/jdk/src/share/classes/sun/security/provider/SeedGenerator.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/provider/SeedGenerator.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/provider/SeedGenerator.java 2020-11-03 06:06:00.736884119 +0000 @@ -179,7 +179,9 @@ // The temporary dir File f = new File(p.getProperty("java.io.tmpdir")); int count = 0; - try (DirectoryStream<Path> stream = Files.newDirectoryStream(f.toPath())) { + DirectoryStream<Path> stream = null; + try { + stream = Files.newDirectoryStream(f.toPath()); // We use a Random object to choose what file names // should be used. Otherwise on a machine with too // many files, the same first 1024 files always get @@ -194,6 +196,10 @@ break; } } + } finally { + if (stream != null) { + stream.close(); + } } } catch (Exception ex) { md.update((byte)ex.hashCode()); diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/tools/jarsigner/Main.java openjdk-boot/jdk/src/share/classes/sun/security/tools/jarsigner/Main.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/tools/jarsigner/Main.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/tools/jarsigner/Main.java 2020-11-03 06:06:00.737884120 +0000 @@ -635,13 +635,15 @@ while (entries.hasMoreElements()) { JarEntry je = entries.nextElement(); entriesVec.addElement(je); - try (InputStream is = jf.getInputStream(je)) { + InputStream is = null; + try { + is = jf.getInputStream(je); String name = je.getName(); if (signatureRelated(name) && SignatureFileVerifier.isBlockOrSF(name)) { String alias = name.substring(name.lastIndexOf('/') + 1, name.lastIndexOf('.')); - try { + try { if (name.endsWith(".SF")) { Manifest sf = new Manifest(is); boolean found = false; @@ -676,8 +678,10 @@ while (is.read(buffer, 0, buffer.length) != -1) { // we just read. this will throw a SecurityException // if a signature/digest check fails. + } } - } + } finally { + if (is != null) { is.close(); } } } @@ -1803,7 +1807,9 @@ // The JarSigner API always accepts the timestamp received. // We need to extract the certs from the signed jar to // validate it. - try (JarFile check = new JarFile(signedJarFile)) { + JarFile check = null; + try { + check = new JarFile(signedJarFile); PKCS7 p7 = new PKCS7(check.getInputStream(check.getEntry( "META-INF/" + sigfile + "." + privateKey.getAlgorithm()))); Timestamp ts = null; @@ -1826,6 +1832,8 @@ if (debug) { e.printStackTrace(); } + } finally { + if (check != null) { try { check.close(); } catch (IOException e) {} } } if (signedjar == null) { diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java openjdk-boot/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java 2020-11-03 06:06:00.737884120 +0000 @@ -114,10 +114,15 @@ return null; } KeyStore caks = null; - try (FileInputStream fis = new FileInputStream(file)) { + FileInputStream fis = null; + try { caks = KeyStore.getInstance(JKS); caks.load(fis, null); - } + } finally { + if (fis != null) { + fis.close(); + } + } return caks; } @@ -150,9 +155,9 @@ } } - try (BufferedReader br = - new BufferedReader(new InputStreamReader( - url.openStream()))) { + BufferedReader br = null; + try { + br = new BufferedReader(new InputStreamReader(url.openStream())); String value = br.readLine(); if (value == null) { @@ -160,7 +165,11 @@ } return value.toCharArray(); - } + } finally { + if (br != null) { + br.close(); + } + } } catch (IOException ioe) { System.err.println(ioe); return null; diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/tools/keytool/Main.java openjdk-boot/jdk/src/share/classes/sun/security/tools/keytool/Main.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/tools/keytool/Main.java 2020-11-02 03:16:29.531281136 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/tools/keytool/Main.java 2020-11-03 06:06:00.738884120 +0000 @@ -965,10 +965,15 @@ // Perform the specified command if (command == CERTREQ) { if (filename != null) { - try (PrintStream ps = new PrintStream(new FileOutputStream - (filename))) { - doCertReq(alias, sigAlgName, ps); - } + PrintStream ps = null; + try { + ps = new PrintStream(new FileOutputStream(filename)); + doCertReq(alias, sigAlgName, ps); + } finally { + if (ps != null) { + ps.close(); + } + } } else { doCertReq(alias, sigAlgName, out); } @@ -984,10 +989,15 @@ kssave = true; } else if (command == EXPORTCERT) { if (filename != null) { - try (PrintStream ps = new PrintStream(new FileOutputStream - (filename))) { + PrintStream ps = null; + try { + ps = new PrintStream(new FileOutputStream(filename)); doExportCert(alias, ps); - } + } finally { + if (ps != null) { + ps.close(); + } + } } else { doExportCert(alias, out); } @@ -1011,9 +1021,15 @@ kssave = true; } else if (command == IDENTITYDB) { if (filename != null) { - try (InputStream inStream = new FileInputStream(filename)) { + InputStream inStream = null; + try { + inStream = new FileInputStream(filename); doImportIdentityDatabase(inStream); - } + } finally { + if (inStream != null) { + inStream.close(); + } + } } else { doImportIdentityDatabase(System.in); } @@ -1144,18 +1160,29 @@ alias = keyAlias; } if (filename != null) { - try (PrintStream ps = - new PrintStream(new FileOutputStream(filename))) { + PrintStream ps = null; + try { + ps = new PrintStream(new FileOutputStream(filename)); doGenCRL(ps); - } + } finally { + if (ps != null) { + ps.close(); + } + } } else { doGenCRL(out); } } else if (command == PRINTCERTREQ) { if (filename != null) { - try (InputStream inStream = new FileInputStream(filename)) { + InputStream inStream = null; + try { + inStream = new FileInputStream(filename); doPrintCertReq(inStream, out); - } + } finally { + if (inStream != null) { + inStream.close(); + } + } } else { doPrintCertReq(System.in, out); } @@ -1181,9 +1208,14 @@ } else { ByteArrayOutputStream bout = new ByteArrayOutputStream(); keyStore.store(bout, pass); - try (FileOutputStream fout = new FileOutputStream(ksfname)) { + FileOutputStream fout = null; + try { + fout = new FileOutputStream(ksfname); fout.write(bout.toByteArray()); - } + } finally { + if (fout != null) + fout.close(); + } } } } @@ -1235,8 +1267,9 @@ private String keyStoreType(File f) throws IOException { int MAGIC = 0xfeedfeed; int JCEKS_MAGIC = 0xcececece; - try (DataInputStream dis = new DataInputStream( - new FileInputStream(f))) { + DataInputStream dis = null; + try { + dis = new DataInputStream(new FileInputStream(f)); int xMagic = dis.readInt(); if (xMagic == MAGIC) { return "JKS"; @@ -1245,6 +1278,8 @@ } else { return "Non JKS/JCEKS"; } + } finally { + if (dis != null) { dis.close(); } } } @@ -2435,13 +2470,19 @@ int pos = 0; while (entries.hasMoreElements()) { JarEntry je = entries.nextElement(); - try (InputStream is = jf.getInputStream(je)) { + InputStream is = null; + try { + is = jf.getInputStream(je); while (is.read(buffer) != -1) { // we just read. this will throw a SecurityException // if a signature/digest check fails. This also // populate the signers } - } + } finally { + if (is != null) { + try { is.close(); } catch (IOException e) {} + } + } CodeSigner[] signers = je.getCodeSigners(); if (signers != null) { for (CodeSigner signer: signers) { @@ -2536,9 +2577,15 @@ } } else { if (filename != null) { - try (FileInputStream inStream = new FileInputStream(filename)) { - printCertFromStream(inStream, out); - } + FileInputStream inStream = null; + try { + inStream = new FileInputStream(filename); + printCertFromStream(inStream, out); + } finally { + if (inStream != null) { + inStream.close(); + } + } } else { printCertFromStream(System.in, out); } diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/util/AnchorCertificates.java openjdk-boot/jdk/src/share/classes/sun/security/util/AnchorCertificates.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/util/AnchorCertificates.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/util/AnchorCertificates.java 2020-11-03 06:06:00.739884120 +0000 @@ -57,7 +57,9 @@ KeyStore cacerts; try { cacerts = KeyStore.getInstance("JKS"); - try (FileInputStream fis = new FileInputStream(f)) { + FileInputStream fis = null; + try { + fis = new FileInputStream(f); cacerts.load(fis, null); certs = new HashSet<>(); Enumeration<String> list = cacerts.aliases(); @@ -71,7 +73,11 @@ certs.add(X509CertImpl.getFingerprint(HASH, cert)); } } - } + } finally { + if (fis != null) { + fis.close(); + } + } } catch (Exception e) { if (debug != null) { debug.println("Error parsing cacerts"); diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/security/util/UntrustedCertificates.java openjdk-boot/jdk/src/share/classes/sun/security/util/UntrustedCertificates.java --- openjdk-boot.orig/jdk/src/share/classes/sun/security/util/UntrustedCertificates.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/security/util/UntrustedCertificates.java 2020-11-03 06:07:14.072861951 +0000 @@ -56,12 +56,24 @@ public Void run() { File f = new File(System.getProperty("java.home"), "lib/security/blacklisted.certs"); - try (FileInputStream fin = new FileInputStream(f)) { + FileInputStream fin = null; + try { + fin = new FileInputStream(f); props.load(fin); } catch (IOException fnfe) { if (debug != null) { debug.println("Error parsing blacklisted.certs"); } + } finally { + try { + if (fin != null) { + fin.close(); + } + } catch (IOException e) { + if (debug != null) { + debug.println("Error closing file: " + e); + } + } } return null; } diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/tools/jcmd/Arguments.java openjdk-boot/jdk/src/share/classes/sun/tools/jcmd/Arguments.java --- openjdk-boot.orig/jdk/src/share/classes/sun/tools/jcmd/Arguments.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/tools/jcmd/Arguments.java 2020-11-03 06:06:00.739884120 +0000 @@ -99,14 +99,19 @@ } private void readCommandFile(String path) throws IOException { - try (BufferedReader bf = new BufferedReader(new FileReader(path));) { - StringBuilder sb = new StringBuilder(); - String s; - while ((s = bf.readLine()) != null) { - sb.append(s).append("\n"); - } - command = sb.toString(); - } + BufferedReader bf = null; + try { + bf = new BufferedReader(new FileReader(path)); + StringBuilder sb = new StringBuilder(); + String s; + while ((s = bf.readLine()) != null) { + sb.append(s).append("\n"); + } + command = sb.toString(); + } finally { + if (bf != null) + bf.close(); + } } public static void usage() { diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/tools/jcmd/JCmd.java openjdk-boot/jdk/src/share/classes/sun/tools/jcmd/JCmd.java --- openjdk-boot.orig/jdk/src/share/classes/sun/tools/jcmd/JCmd.java 2020-11-02 03:16:29.539281144 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/tools/jcmd/JCmd.java 2020-11-03 06:06:00.739884120 +0000 @@ -116,7 +116,7 @@ e.printStackTrace(); } } - } + } } if (pids.isEmpty()) { System.err.println("Could not find any processes matching : '" @@ -158,7 +158,9 @@ if (line.trim().equals("stop")) { break; } - try (InputStream in = hvm.executeJCmd(line);) { + InputStream in = null; + try { + in = hvm.executeJCmd(line); // read to EOF and just print output byte b[] = new byte[256]; int n; @@ -169,6 +171,9 @@ System.out.print(s); } } while (n > 0); + } finally { + if (in != null) + in.close(); } } vm.detach(); @@ -205,8 +210,8 @@ } catch (URISyntaxException ex) { return false; } catch (MonitorException ex) { - return false; - } + return false; + } } private static String getMainClass(VirtualMachineDescriptor vmd) diff -Nru openjdk-boot.orig/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java openjdk-boot/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java --- openjdk-boot.orig/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java 2020-11-03 06:06:00.740884120 +0000 @@ -126,9 +126,15 @@ calendarProps = AccessController.doPrivileged(new PrivilegedExceptionAction<Properties>() { public Properties run() throws IOException { Properties props = new Properties(); - try (FileInputStream fis = new FileInputStream(fname)) { + FileInputStream fis = null; + try { + fis = new FileInputStream(fname); props.load(fis); } + finally { + if (fis != null) + fis.close(); + } return props; } }); diff -Nru openjdk-boot.orig/jdk/src/share/demo/jfc/Font2DTest/RangeMenu.java openjdk-boot/jdk/src/share/demo/jfc/Font2DTest/RangeMenu.java --- openjdk-boot.orig/jdk/src/share/demo/jfc/Font2DTest/RangeMenu.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/share/demo/jfc/Font2DTest/RangeMenu.java 2020-11-03 06:06:00.740884120 +0000 @@ -200,7 +200,7 @@ } private static int[][] getUnicodeRanges() { - List<Integer> ranges = new ArrayList<>(); + List<Integer> ranges = new ArrayList<Integer>(); ranges.add(0); Character.UnicodeBlock currentBlock = Character.UnicodeBlock.of(0); for (int cp = 0x000001; cp < 0x110000; cp++ ) { diff -Nru openjdk-boot.orig/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java openjdk-boot/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java --- openjdk-boot.orig/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java 2020-11-03 06:06:00.740884120 +0000 @@ -569,11 +569,11 @@ public Void run() throws BackingStoreException { Map<String, String> m = new TreeMap<>(); long newLastSyncTime = 0; + FileInputStream fis = null; try { newLastSyncTime = prefsFile.lastModified(); - try (FileInputStream fis = new FileInputStream(prefsFile)) { - XmlSupport.importMap(fis, m); - } + fis = new FileInputStream(prefsFile); + XmlSupport.importMap(fis, m); } catch(Exception e) { if (e instanceof InvalidPreferencesFormatException) { getLogger().warning("Invalid preferences format in " @@ -588,6 +588,13 @@ } else { throw new BackingStoreException(e); } + } finally { + try { + if (fis != null) + fis.close(); + } catch (IOException e) { + throw new BackingStoreException(e); + } } // Attempt succeeded; update state prefsCache = m; @@ -614,13 +621,14 @@ AccessController.doPrivileged( new PrivilegedExceptionAction<Void>() { public Void run() throws BackingStoreException { + FileOutputStream fos = null; try { if (!dir.exists() && !dir.mkdirs()) throw new BackingStoreException(dir + " create failed."); - try (FileOutputStream fos = new FileOutputStream(tmpFile)) { - XmlSupport.exportMap(fos, prefsCache); - } + + fos = new FileOutputStream(tmpFile); + XmlSupport.exportMap(fos, prefsCache); if (!tmpFile.renameTo(prefsFile)) throw new BackingStoreException("Can't rename " + tmpFile + " to " + prefsFile); @@ -629,6 +637,14 @@ throw (BackingStoreException)e; throw new BackingStoreException(e); } + finally { + try { + if (fos != null) + fos.close(); + } catch (IOException e) { + throw new BackingStoreException(e); + } + } return null; } }); diff -Nru openjdk-boot.orig/jdk/src/solaris/classes/sun/nio/fs/UnixFileStore.java openjdk-boot/jdk/src/solaris/classes/sun/nio/fs/UnixFileStore.java --- openjdk-boot.orig/jdk/src/solaris/classes/sun/nio/fs/UnixFileStore.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/solaris/classes/sun/nio/fs/UnixFileStore.java 2020-11-03 06:06:00.741884119 +0000 @@ -256,9 +256,16 @@ String fstypes = System.getProperty("java.home") + "/lib/fstypes.properties"; Path file = Paths.get(fstypes); try { - try (ReadableByteChannel rbc = Files.newByteChannel(file)) { + ReadableByteChannel rbc = null; + try { + rbc = Files.newByteChannel(file); result.load(Channels.newReader(rbc, "UTF-8")); } + finally { + if (rbc != null) { + rbc.close(); + } + } } catch (IOException x) { } return result; diff -Nru openjdk-boot.orig/jdk/src/solaris/classes/sun/print/UnixPrintJob.java openjdk-boot/jdk/src/solaris/classes/sun/print/UnixPrintJob.java --- openjdk-boot.orig/jdk/src/solaris/classes/sun/print/UnixPrintJob.java 2020-11-02 02:26:27.000000000 +0000 +++ openjdk-boot/jdk/src/solaris/classes/sun/print/UnixPrintJob.java 2020-11-03 06:06:00.741884119 +0000 @@ -960,25 +960,38 @@ private void handleProcessFailure(final Process failedProcess, final String[] execCmd, final int result) throws IOException { - try (StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw)) { + StringWriter sw = null; + PrintWriter pw = null; + try { + sw = new StringWriter(); + pw = new PrintWriter(sw); pw.append("error=").append(Integer.toString(result)); pw.append(" running:"); for (String arg: execCmd) { pw.append(" '").append(arg).append("'"); } - try (InputStream is = failedProcess.getErrorStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr)) { + InputStream is = null; + InputStreamReader isr = null; + BufferedReader br = null; + try { + is = failedProcess.getErrorStream(); + isr = new InputStreamReader(is); + br = new BufferedReader(isr); while (br.ready()) { pw.println(); pw.append("\t\t").append(br.readLine()); } } finally { pw.flush(); + if (br != null) br.close(); + if (isr != null) isr.close(); + if (is != null) is.close(); throw new IOException(sw.toString()); } - } + } finally { + if (pw != null) pw.close(); + if (sw != null) sw.close(); + } } public Object run() {