mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8202324: Avoid loading FileInput-/OutputStream$AltFinalizer
Reviewed-by: alanb
This commit is contained in:
parent
a7b8407fbc
commit
dce2872700
2 changed files with 41 additions and 42 deletions
|
@ -79,7 +79,7 @@ class FileInputStream extends InputStream
|
|||
|
||||
private volatile boolean closed;
|
||||
|
||||
private final AltFinalizer altFinalizer;
|
||||
private final Object altFinalizer;
|
||||
|
||||
/**
|
||||
* Creates a <code>FileInputStream</code> by
|
||||
|
@ -155,7 +155,7 @@ class FileInputStream extends InputStream
|
|||
fd.attach(this);
|
||||
path = name;
|
||||
open(name);
|
||||
altFinalizer = AltFinalizer.get(this);
|
||||
altFinalizer = getFinalizer(this);
|
||||
if (altFinalizer == null) {
|
||||
FileCleanable.register(fd); // open set the fd, register the cleanup
|
||||
}
|
||||
|
@ -471,6 +471,23 @@ class FileInputStream extends InputStream
|
|||
protected void finalize() throws IOException {
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a finalizer object if the FIS needs a finalizer; otherwise null.
|
||||
* If the FIS has a close method; it needs an AltFinalizer.
|
||||
*/
|
||||
private static Object getFinalizer(FileInputStream fis) {
|
||||
Class<?> clazz = fis.getClass();
|
||||
while (clazz != FileInputStream.class) {
|
||||
try {
|
||||
clazz.getDeclaredMethod("close");
|
||||
return new AltFinalizer(fis);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
// ignore
|
||||
}
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Class to call {@code FileInputStream.close} when finalized.
|
||||
* If finalization of the stream is needed, an instance is created
|
||||
|
@ -481,25 +498,7 @@ class FileInputStream extends InputStream
|
|||
static class AltFinalizer {
|
||||
private final FileInputStream fis;
|
||||
|
||||
/*
|
||||
* Returns a finalizer object if the FIS needs a finalizer; otherwise null.
|
||||
* If the FIS has a close method; it needs an AltFinalizer.
|
||||
*/
|
||||
static AltFinalizer get(FileInputStream fis) {
|
||||
Class<?> clazz = fis.getClass();
|
||||
while (clazz != FileInputStream.class) {
|
||||
try {
|
||||
clazz.getDeclaredMethod("close");
|
||||
return new AltFinalizer(fis);
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
// ignore
|
||||
}
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private AltFinalizer(FileInputStream fis) {
|
||||
AltFinalizer(FileInputStream fis) {
|
||||
this.fis = fis;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue