8027992: FileInputStream and BufferedInputStream should be closed in sun.applet.*

Reviewed-by: anthony, serb
This commit is contained in:
Petr Pchelko 2013-11-18 19:22:29 +04:00
parent c63514c9aa
commit 5bd2a99aa1
3 changed files with 17 additions and 34 deletions

View File

@ -794,18 +794,13 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable {
doInit = true; doInit = true;
} else { } else {
// serName is not null; // serName is not null;
InputStream is = (InputStream) try (InputStream is = AccessController.doPrivileged(
java.security.AccessController.doPrivileged( (PrivilegedAction<InputStream>)() -> loader.getResourceAsStream(serName));
new java.security.PrivilegedAction() { ObjectInputStream ois = new AppletObjectInputStream(is, loader)) {
public Object run() {
return loader.getResourceAsStream(serName); applet = (Applet) ois.readObject();
} doInit = false; // skip over the first init
}); }
ObjectInputStream ois =
new AppletObjectInputStream(is, loader);
Object serObject = ois.readObject();
applet = (Applet) serObject;
doInit = false; // skip over the first init
} }
// Determine the JDK level that the applet targets. // Determine the JDK level that the applet targets.
@ -1239,20 +1234,13 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable {
// append .class // append .class
final String resourceName = name + ".class"; final String resourceName = name + ".class";
InputStream is = null;
byte[] classHeader = new byte[8]; byte[] classHeader = new byte[8];
try { try (InputStream is = AccessController.doPrivileged(
is = (InputStream) java.security.AccessController.doPrivileged( (PrivilegedAction<InputStream>) () -> loader.getResourceAsStream(resourceName))) {
new java.security.PrivilegedAction() {
public Object run() {
return loader.getResourceAsStream(resourceName);
}
});
// Read the first 8 bytes of the class file // Read the first 8 bytes of the class file
int byteRead = is.read(classHeader, 0, 8); int byteRead = is.read(classHeader, 0, 8);
is.close();
// return if the header is not read in entirely // return if the header is not read in entirely
// for some reasons. // for some reasons.

View File

@ -668,11 +668,11 @@ public class AppletViewer extends Frame implements AppletContext,
String dname = fd.getDirectory(); String dname = fd.getDirectory();
File file = new File(dname, fname); File file = new File(dname, fname);
try { try (FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream s = new BufferedOutputStream(new FileOutputStream(file)); BufferedOutputStream bos = new BufferedOutputStream(fos);
ObjectOutputStream os = new ObjectOutputStream(s); ObjectOutputStream os = new ObjectOutputStream(bos)) {
showStatus(amh.getMessage("appletsave.err1",
panel.applet.toString(), file.toString())); showStatus(amh.getMessage("appletsave.err1", panel.applet.toString(), file.toString()));
os.writeObject(panel.applet); os.writeObject(panel.applet);
} catch (IOException ex) { } catch (IOException ex) {
System.err.println(amh.getMessage("appletsave.err2", ex)); System.err.println(amh.getMessage("appletsave.err2", ex));

View File

@ -432,10 +432,8 @@ public class Main {
} }
// SAVE THE FILE // SAVE THE FILE
try { try (FileOutputStream out = new FileOutputStream(dotAV)) {
FileOutputStream out = new FileOutputStream(dotAV);
avProps.store(out, lookup("main.prop.store")); avProps.store(out, lookup("main.prop.store"));
out.close();
} catch (IOException e) { } catch (IOException e) {
System.err.println(lookup("main.err.prop.cantsave", System.err.println(lookup("main.err.prop.cantsave",
dotAV.toString())); dotAV.toString()));
@ -472,13 +470,10 @@ public class Main {
// read the file // read the file
Properties tmpProps = new Properties(); Properties tmpProps = new Properties();
try { try (FileInputStream in = new FileInputStream(inFile)) {
FileInputStream in = new FileInputStream(inFile);
tmpProps.load(new BufferedInputStream(in)); tmpProps.load(new BufferedInputStream(in));
in.close();
} catch (IOException e) { } catch (IOException e) {
System.err.println(lookup("main.err.prop.cantread", System.err.println(lookup("main.err.prop.cantread", inFile.toString()));
inFile.toString()));
} }
// pick off the properties we care about // pick off the properties we care about