8212129: Remove finalize methods from java.util.zip.ZipFIle/Inflator/Deflator

Reviewed-by: rriggs, sherman, alanb, clanger
This commit is contained in:
Lance Andersen 2018-10-26 14:02:31 -04:00
parent 0108d754d7
commit a655e6b52b
5 changed files with 4 additions and 396 deletions

View file

@ -87,13 +87,6 @@ import sun.nio.ch.DirectBuffer;
* to perform cleanup should be modified to use alternative cleanup mechanisms such
* as {@link java.lang.ref.Cleaner} and remove the overriding {@code finalize} method.
*
* @implSpec
* If this {@code Inflater} has been subclassed and the {@code end} method has been
* overridden, the {@code end} method will be called by the finalization when the
* inflater is unreachable. But the subclasses should not depend on this specific
* implementation; the finalization is not reliable and the {@code finalize} method
* is deprecated to be removed.
*
* @see Deflater
* @author David Connelly
* @since 1.1
@ -135,7 +128,7 @@ public class Inflater {
* @param nowrap if true then support GZIP compatible compression
*/
public Inflater(boolean nowrap) {
this.zsRef = InflaterZStreamRef.get(this, init(nowrap));
this.zsRef = new InflaterZStreamRef(this, init(nowrap));
}
/**
@ -714,25 +707,6 @@ public class Inflater {
}
}
/**
* Closes the decompressor when garbage is collected.
*
* @implSpec
* If this {@code Inflater} has been subclassed and the {@code end} method
* has been overridden, the {@code end} method will be called when the
* inflater is unreachable.
*
* @deprecated The {@code finalize} method has been deprecated and will be
* removed. It is implemented as a no-op. Subclasses that override
* {@code finalize} in order to perform cleanup should be modified to use
* alternative cleanup mechanisms and remove the overriding {@code finalize}
* method. The recommended cleanup for compressor is to explicitly call
* {@code end} method when it is no longer in use. If the {@code end} is
* not invoked explicitly the resource of the compressor will be released
* when the instance becomes unreachable,
*/
@Deprecated(since="9", forRemoval=true)
protected void finalize() {}
private void ensureOpen () {
assert Thread.holdsLock(zsRef);
@ -792,43 +766,5 @@ public class Inflater {
}
}
/*
* If {@code Inflater} has been subclassed and the {@code end} method is
* overridden, uses {@code finalizer} mechanism for resource cleanup. So
* {@code end} method can be called when the {@code Inflater} is unreachable.
* This mechanism will be removed when the {@code finalize} method is
* removed from {@code Inflater}.
*/
static InflaterZStreamRef get(Inflater owner, long addr) {
Class<?> clz = owner.getClass();
while (clz != Inflater.class) {
try {
clz.getDeclaredMethod("end");
return new FinalizableZStreamRef(owner, addr);
} catch (NoSuchMethodException nsme) {}
clz = clz.getSuperclass();
}
return new InflaterZStreamRef(owner, addr);
}
private static class FinalizableZStreamRef extends InflaterZStreamRef {
final Inflater owner;
FinalizableZStreamRef(Inflater owner, long addr) {
super(null, addr);
this.owner = owner;
}
@Override
void clean() {
run();
}
@Override
@SuppressWarnings("deprecation")
protected void finalize() {
owner.end();
}
}
}
}