8276447: Deprecate finalization-related methods for removal

Reviewed-by: rriggs, alanb, lancea, darcy, mchung, serb, smarks, prr
This commit is contained in:
Brent Christian 2021-12-08 00:23:15 +00:00
parent 3c2951f738
commit ec7cb6d5d3
62 changed files with 156 additions and 140 deletions
src
java.base/share/classes
java.desktop
java.management/share/classes
java/lang/management
sun/management
java.naming/share/classes/com/sun/jndi/ldap
java.rmi/share/classes/sun/rmi/log
java.security.jgss/share/classes/sun/security/jgss/wrapper
java.security.sasl/share/classes/com/sun/security/sasl
java.smartcardio/share/classes/sun/security/smartcardio
jdk.crypto.cryptoki/share/classes/sun/security/pkcs11
jdk.crypto.mscapi/windows/classes/sun/security/mscapi
jdk.jconsole/share/classes/sun/tools/jconsole
jdk.jfr/share/classes/jdk/jfr/internal
jdk.naming.dns/share/classes/com/sun/jndi/dns
jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry
jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb
jdk.zipfs/share/classes/jdk/nio/zipfs

@ -275,8 +275,13 @@ public abstract class Enum<E extends Enum<E>>
/** /**
* enum classes cannot have finalize methods. * enum classes cannot have finalize methods.
*
* @deprecated Finalization has been deprecated for removal. See
* {@link java.lang.Object#finalize} for background information and details
* about migration options.
*/ */
@SuppressWarnings("deprecation") @Deprecated(since="18", forRemoval=true)
@SuppressWarnings("removal")
protected final void finalize() { } protected final void finalize() { }
/** /**

@ -478,6 +478,12 @@ public class Object {
* A subclass overrides the {@code finalize} method to dispose of * A subclass overrides the {@code finalize} method to dispose of
* system resources or to perform other cleanup. * system resources or to perform other cleanup.
* <p> * <p>
* <b>When running in a Java virtual machine in which finalization has been
* disabled or removed, the garbage collector will never call
* {@code finalize()}. In a Java virtual machine in which finalization is
* enabled, the garbage collector might call {@code finalize} only after an
* indefinite delay.</b>
* <p>
* The general contract of {@code finalize} is that it is invoked * The general contract of {@code finalize} is that it is invoked
* if and when the Java virtual * if and when the Java virtual
* machine has determined that there is no longer any * machine has determined that there is no longer any
@ -543,27 +549,29 @@ public class Object {
* } * }
* }</pre> * }</pre>
* *
* @deprecated The finalization mechanism is inherently problematic. * @deprecated Finalization is deprecated and subject to removal in a future
* Finalization can lead to performance issues, deadlocks, and hangs. * release. The use of finalization can lead to problems with security,
* Errors in finalizers can lead to resource leaks; there is no way to cancel * performance, and reliability.
* finalization if it is no longer necessary; and no ordering is specified * See <a href="https://openjdk.java.net/jeps/421">JEP 421</a> for
* among calls to {@code finalize} methods of different objects. * discussion and alternatives.
* Furthermore, there are no guarantees regarding the timing of finalization. * <p>
* The {@code finalize} method might be called on a finalizable object * Subclasses that override {@code finalize} to perform cleanup should use
* only after an indefinite delay, if at all. * alternative cleanup mechanisms and remove the {@code finalize} method.
* * Use {@link java.lang.ref.Cleaner} and
* Classes whose instances hold non-heap resources should provide a method * {@link java.lang.ref.PhantomReference} as safer ways to release resources
* to enable explicit release of those resources, and they should also * when an object becomes unreachable. Alternatively, add a {@code close}
* implement {@link AutoCloseable} if appropriate. * method to explicitly release resources, and implement
* The {@link java.lang.ref.Cleaner} and {@link java.lang.ref.PhantomReference} * {@code AutoCloseable} to enable use of the {@code try}-with-resources
* provide more flexible and efficient ways to release resources when an object * statement.
* becomes unreachable. * <p>
* This method will remain in place until finalizers have been removed from
* most existing code.
* *
* @throws Throwable the {@code Exception} raised by this method * @throws Throwable the {@code Exception} raised by this method
* @see java.lang.ref.WeakReference * @see java.lang.ref.WeakReference
* @see java.lang.ref.PhantomReference * @see java.lang.ref.PhantomReference
* @jls 12.6 Finalization of Class Instances * @jls 12.6 Finalization of Class Instances
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
protected void finalize() throws Throwable { } protected void finalize() throws Throwable { }
} }

@ -707,8 +707,17 @@ public class Runtime {
* The method {@link System#runFinalization()} is the conventional * The method {@link System#runFinalization()} is the conventional
* and convenient means of invoking this method. * and convenient means of invoking this method.
* *
* @deprecated Finalization has been deprecated for removal. See
* {@link java.lang.Object#finalize} for background information and details
* about migration options.
* <p>
* When running in a JVM in which finalization has been disabled or removed,
* no objects will be pending finalization, so this method does nothing.
*
* @see java.lang.Object#finalize() * @see java.lang.Object#finalize()
* @jls 12.6 Finalization of Class Instances
*/ */
@Deprecated(since="18", forRemoval=true)
public void runFinalization() { public void runFinalization() {
SharedSecrets.getJavaLangRefAccess().runFinalization(); SharedSecrets.getJavaLangRefAccess().runFinalization();
} }

@ -1922,8 +1922,18 @@ public final class System {
* Runtime.getRuntime().runFinalization() * Runtime.getRuntime().runFinalization()
* </pre></blockquote> * </pre></blockquote>
* *
* @deprecated Finalization has been deprecated for removal. See
* {@link java.lang.Object#finalize} for background information and details
* about migration options.
* <p>
* When running in a JVM in which finalization has been disabled or removed,
* no objects will be pending finalization, so this method does nothing.
*
* @see java.lang.Runtime#runFinalization() * @see java.lang.Runtime#runFinalization()
* @jls 12.6 Finalization of Class Instances
*/ */
@Deprecated(since="18", forRemoval=true)
@SuppressWarnings("removal")
public static void runFinalization() { public static void runFinalization() {
Runtime.getRuntime().runFinalization(); Runtime.getRuntime().runFinalization();
} }
@ -2321,7 +2331,7 @@ public final class System {
public Thread newThreadWithAcc(Runnable target, @SuppressWarnings("removal") AccessControlContext acc) { public Thread newThreadWithAcc(Runnable target, @SuppressWarnings("removal") AccessControlContext acc) {
return new Thread(target, acc); return new Thread(target, acc);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
public void invokeFinalize(Object o) throws Throwable { public void invokeFinalize(Object o) throws Throwable {
o.finalize(); o.finalize();
} }

@ -791,7 +791,7 @@ public class Executors {
FinalizableDelegatedExecutorService(ExecutorService executor) { FinalizableDelegatedExecutorService(ExecutorService executor) {
super(executor); super(executor);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
super.shutdown(); super.shutdown();
} }

@ -1477,8 +1477,13 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
* @implNote Previous versions of this class had a finalize method * @implNote Previous versions of this class had a finalize method
* that shut down this executor, but in this version, finalize * that shut down this executor, but in this version, finalize
* does nothing. * does nothing.
*
* @deprecated Finalization has been deprecated for removal. See
* {@link java.lang.Object#finalize} for background information and details
* about migration options.
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
protected void finalize() {} protected void finalize() {}
/** /**

@ -242,7 +242,7 @@ public class MeteredStream extends FilterInputStream {
return readLock.isHeldByCurrentThread(); return readLock.isHeldByCurrentThread();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
close(); close();

@ -270,7 +270,7 @@ abstract class BaseSSLSocketImpl extends SSLSocket {
* the penalty of prematurly killing SSL sessions. * the penalty of prematurly killing SSL sessions.
*/ */
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected final void finalize() throws Throwable { protected final void finalize() throws Throwable {
try { try {
close(); close();

@ -114,7 +114,7 @@ public final class JRSUIControl {
changes.putAll(other.changes); changes.putAll(other.changes);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected synchronized void finalize() throws Throwable { protected synchronized void finalize() throws Throwable {
if (cfDictionaryPtr == 0) return; if (cfDictionaryPtr == 0) return;
disposeCFDictionary(cfDictionaryPtr); disposeCFDictionary(cfDictionaryPtr);

@ -144,7 +144,7 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment {
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
super.finalize(); super.finalize();

@ -247,7 +247,7 @@ public final class CFont extends PhysicalFont implements FontSubstitution {
return compFont; return compFont;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected synchronized void finalize() { protected synchronized void finalize() {
if (nativeFontPtr != 0) { if (nativeFontPtr != 0) {
disposeNativeFont(nativeFontPtr); disposeNativeFont(nativeFontPtr);

@ -125,7 +125,7 @@ public final class CStrike extends PhysicalStrike {
return nativeStrikePtr; return nativeStrikePtr;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected synchronized void finalize() throws Throwable { protected synchronized void finalize() throws Throwable {
if (nativeStrikePtr != 0) { if (nativeStrikePtr != 0) {
disposeNativeStrikePtr(nativeStrikePtr); disposeNativeStrikePtr(nativeStrikePtr);

@ -163,7 +163,7 @@ public class CFRetainedResource {
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected final void finalize() throws Throwable { protected final void finalize() throws Throwable {
dispose(); dispose();
} }

@ -598,7 +598,7 @@ public final class CPrinterJob extends RasterPrinterJob {
// The following methods are CPrinterJob specific. // The following methods are CPrinterJob specific.
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
synchronized (fNSPrintInfoLock) { synchronized (fNSPrintInfoLock) {
if (fNSPrintInfo != -1) { if (fNSPrintInfo != -1) {

@ -72,7 +72,7 @@ public final class SubImageInputStream extends ImageInputStreamImpl {
streamPos = pos; streamPos = pos;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// Empty finalizer (for improved performance; no need to call // Empty finalizer (for improved performance; no need to call
// super.finalize() in this case) // super.finalize() in this case)

@ -147,7 +147,7 @@ final class ChunkStream extends ImageOutputStreamImpl {
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// Empty finalizer (for improved performance; no need to call // Empty finalizer (for improved performance; no need to call
// super.finalize() in this case) // super.finalize() in this case)
@ -284,7 +284,7 @@ final class IDATOutputStream extends ImageOutputStreamImpl {
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// Empty finalizer (for improved performance; no need to call // Empty finalizer (for improved performance; no need to call
// super.finalize() in this case) // super.finalize() in this case)

@ -435,7 +435,7 @@ public abstract class TIFFBaseJPEGCompressor extends TIFFCompressor {
return compDataLength; return compDataLength;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
super.finalize(); super.finalize();
if(JPEGWriter != null) { if(JPEGWriter != null) {

@ -139,7 +139,7 @@ public class TIFFJPEGDecompressor extends TIFFDecompressor {
JPEGReader.read(0, JPEGParam); JPEGReader.read(0, JPEGParam);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
super.finalize(); super.finalize();
JPEGReader.dispose(); JPEGReader.dispose();

@ -610,7 +610,7 @@ public class TIFFOldJPEGDecompressor extends TIFFJPEGDecompressor {
JPEGReader.read(0, JPEGParam); JPEGReader.read(0, JPEGParam);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
super.finalize(); super.finalize();
JPEGReader.dispose(); JPEGReader.dispose();

@ -60,7 +60,7 @@ public class StreamFinalizer {
this.stream = stream; this.stream = stream;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
stream.close(); stream.close();

@ -425,7 +425,7 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
* close this device if discarded by the garbage collector. * close this device if discarded by the garbage collector.
*/ */
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected final void finalize() { protected final void finalize() {
close(); close();
} }

@ -283,6 +283,7 @@ public final class JavaSoundAudioClip implements AudioClip, MetaEventListener, L
} }
@Override @Override
@SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
if (clip != null) { if (clip != null) {

@ -1162,17 +1162,14 @@ public abstract class Graphics {
/** /**
* Disposes of this graphics context once it is no longer referenced. * Disposes of this graphics context once it is no longer referenced.
* *
* @deprecated The {@code finalize} method has been deprecated. * @deprecated Finalization has been deprecated for removal. See
* Subclasses that override {@code finalize} in order to perform cleanup * {@link java.lang.Object#finalize} for background information and details
* should be modified to use alternative cleanup mechanisms and * about migration options.
* to remove the overriding {@code finalize} method. *
* When overriding the {@code finalize} method, its implementation must explicitly
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
* See the specification for {@link Object#finalize()} for further
* information about migration options.
* @see #dispose * @see #dispose
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
public void finalize() { public void finalize() {
dispose(); dispose();
} }

@ -85,17 +85,14 @@ public abstract class PrintJob {
/** /**
* Ends this print job once it is no longer referenced. * Ends this print job once it is no longer referenced.
* *
* @deprecated The {@code finalize} method has been deprecated. * @deprecated Finalization has been deprecated for removal. See
* Subclasses that override {@code finalize} in order to perform cleanup * {@link java.lang.Object#finalize} for background information and details
* should be modified to use alternative cleanup mechanisms and * about migration options.
* to remove the overriding {@code finalize} method. *
* When overriding the {@code finalize} method, its implementation must explicitly
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
* See the specification for {@link Object#finalize()} for further
* information about migration options.
* @see #end * @see #end
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
public void finalize() { public void finalize() {
end(); end();
} }

@ -680,16 +680,12 @@ public class ServiceRegistry {
* @exception Throwable if an error occurs during superclass * @exception Throwable if an error occurs during superclass
* finalization. * finalization.
* *
* @deprecated The {@code finalize} method has been deprecated. * @deprecated Finalization has been deprecated for removal. See
* Subclasses that override {@code finalize} in order to perform cleanup * {@link java.lang.Object#finalize} for background information and details
* should be modified to use alternative cleanup mechanisms and * about migration options.
* to remove the overriding {@code finalize} method.
* When overriding the {@code finalize} method, its implementation must explicitly
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
* See the specification for {@link Object#finalize()} for further
* information about migration options.
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
public void finalize() throws Throwable { public void finalize() throws Throwable {
deregisterAll(); deregisterAll();
super.finalize(); super.finalize();
@ -842,7 +838,7 @@ class SubRegistry {
accMap.clear(); accMap.clear();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
public synchronized void finalize() { public synchronized void finalize() {
clear(); clear();
} }

@ -261,16 +261,12 @@ public class FileCacheImageInputStream extends ImageInputStreamImpl {
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @deprecated The {@code finalize} method has been deprecated. * @deprecated Finalization has been deprecated for removal. See
* Subclasses that override {@code finalize} in order to perform cleanup * {@link java.lang.Object#finalize} for background information and details
* should be modified to use alternative cleanup mechanisms and * about migration options.
* to remove the overriding {@code finalize} method.
* When overriding the {@code finalize} method, its implementation must explicitly
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
* See the specification for {@link Object#finalize()} for further
* information about migration options.
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the // Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying // Disposer mechanism for ensuring that the underlying

@ -156,16 +156,12 @@ public class FileImageInputStream extends ImageInputStreamImpl {
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @deprecated The {@code finalize} method has been deprecated. * @deprecated Finalization has been deprecated for removal. See
* Subclasses that override {@code finalize} in order to perform cleanup * {@link java.lang.Object#finalize} for background information and details
* should be modified to use alternative cleanup mechanisms and * about migration options.
* to remove the overriding {@code finalize} method.
* When overriding the {@code finalize} method, its implementation must explicitly
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
* See the specification for {@link Object#finalize()} for further
* information about migration options.
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the // Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying // Disposer mechanism for ensuring that the underlying

@ -164,16 +164,12 @@ public class FileImageOutputStream extends ImageOutputStreamImpl {
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @deprecated The {@code finalize} method has been deprecated. * @deprecated Finalization has been deprecated for removal. See
* Subclasses that override {@code finalize} in order to perform cleanup * {@link java.lang.Object#finalize} for background information and details
* should be modified to use alternative cleanup mechanisms and * about migration options.
* to remove the overriding {@code finalize} method.
* When overriding the {@code finalize} method, its implementation must explicitly
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
* See the specification for {@link Object#finalize()} for further
* information about migration options.
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the // Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying // Disposer mechanism for ensuring that the underlying

@ -868,16 +868,12 @@ public abstract class ImageInputStreamImpl implements ImageInputStream {
* @exception Throwable if an error occurs during superclass * @exception Throwable if an error occurs during superclass
* finalization. * finalization.
* *
* @deprecated The {@code finalize} method has been deprecated. * @deprecated Finalization has been deprecated for removal. See
* Subclasses that override {@code finalize} in order to perform cleanup * {@link java.lang.Object#finalize} for background information and details
* should be modified to use alternative cleanup mechanisms and * about migration options.
* to remove the overriding {@code finalize} method.
* When overriding the {@code finalize} method, its implementation must explicitly
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
* See the specification for {@link Object#finalize()} for further
* information about migration options.
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if (!isClosed) { if (!isClosed) {
try { try {

@ -179,16 +179,12 @@ public class MemoryCacheImageInputStream extends ImageInputStreamImpl {
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @deprecated The {@code finalize} method has been deprecated. * @deprecated Finalization has been deprecated for removal. See
* Subclasses that override {@code finalize} in order to perform cleanup * {@link java.lang.Object#finalize} for background information and details
* should be modified to use alternative cleanup mechanisms and * about migration options.
* to remove the overriding {@code finalize} method.
* When overriding the {@code finalize} method, its implementation must explicitly
* ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
* See the specification for {@link Object#finalize()} for further
* information about migration options.
*/ */
@Deprecated(since="9") @Deprecated(since="9", forRemoval=true)
@SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the // Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying // Disposer mechanism for ensuring that the underlying

@ -350,7 +350,7 @@ public final class StringContent implements AbstractDocument.Content, Serializab
return rec.offset; return rec.offset;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
// schedule the record to be removed later // schedule the record to be removed later
// on another thread. // on another thread.

@ -3656,7 +3656,7 @@ public final class SunGraphics2D
* enough to know that if our override is empty then it should not * enough to know that if our override is empty then it should not
* mark us as finalizeable. * mark us as finalizeable.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
public void finalize() { public void finalize() {
// DO NOT REMOVE THIS METHOD // DO NOT REMOVE THIS METHOD
} }

@ -1336,7 +1336,7 @@ public class PeekGraphics extends Graphics2D
/** /**
* Empty finalizer as no clean up needed here. * Empty finalizer as no clean up needed here.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
public void finalize() { public void finalize() {
} }

@ -940,7 +940,7 @@ public class PrintJob2D extends PrintJob implements Printable, Runnable {
* Ends this print job once it is no longer referenced. * Ends this print job once it is no longer referenced.
* @see #end * @see #end
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
public void finalize() { public void finalize() {
end(); end();
} }

@ -1099,7 +1099,7 @@ public class ProxyGraphics extends Graphics {
/** /**
* Empty finalizer as no clean up needed here. * Empty finalizer as no clean up needed here.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
public void finalize() { public void finalize() {
} }

@ -1264,7 +1264,7 @@ public class ProxyGraphics2D extends Graphics2D implements PrinterGraphics {
/** /**
* Empty finalizer as no clean up needed here. * Empty finalizer as no clean up needed here.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
public void finalize() { public void finalize() {
} }

@ -172,7 +172,7 @@ public abstract class X11InputMethodBase extends InputMethodAdapter {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
dispose(); dispose();
super.finalize(); super.finalize();

@ -133,7 +133,7 @@ final class WInputMethod extends InputMethodAdapter
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable protected void finalize() throws Throwable
{ {
// Release the resources used by the native input context. // Release the resources used by the native input context.

@ -207,9 +207,15 @@ public interface MemoryMXBean extends PlatformManagedObject {
* Returns the approximate number of objects for which * Returns the approximate number of objects for which
* finalization is pending. * finalization is pending.
* *
* @deprecated Finalization has been deprecated for removal. See
* {@link java.lang.Object#finalize} for details.
*
* @return the approximate number objects for which finalization * @return the approximate number objects for which finalization
* is pending. * is pending. If this MemoryMXBean contains information about a JVM in
* which finalization has been disabled or removed, this method always
* returns zero.
*/ */
@Deprecated(since="18")
public int getObjectPendingFinalizationCount(); public int getObjectPendingFinalizationCount();
/** /**

@ -58,6 +58,7 @@ class MemoryImpl extends NotificationEmitterSupport
this.jvm = vm; this.jvm = vm;
} }
@SuppressWarnings("deprecation")
public int getObjectPendingFinalizationCount() { public int getObjectPendingFinalizationCount() {
return jdk.internal.misc.VM.getFinalRefCount(); return jdk.internal.misc.VM.getFinalRefCount();
} }

@ -383,7 +383,7 @@ abstract class AbstractLdapNamingEnumeration<T extends NameClassPair>
listArg = ne.listArg; listArg = ne.listArg;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected final void finalize() { protected final void finalize() {
cleanup(); cleanup();
} }

@ -477,7 +477,7 @@ public final class LdapClient implements PooledConnection {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
if (debug > 0) System.err.println("LdapClient: finalize " + this); if (debug > 0) System.err.println("LdapClient: finalize " + this);
forceClose(pooled); forceClose(pooled);

@ -2639,7 +2639,7 @@ public final class LdapCtx extends ComponentDirContext
// ----------------- Connection --------------------- // ----------------- Connection ---------------------
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
try { try {
close(); close();

@ -131,7 +131,7 @@ final class DefaultCallbackHandler implements CallbackHandler {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
clearPassword(); clearPassword();
} }

@ -128,7 +128,7 @@ class LogInputStream extends InputStream {
/** /**
* Closes the stream when garbage is collected. * Closes the stream when garbage is collected.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws IOException { protected void finalize() throws IOException {
close(); close();
} }

@ -132,7 +132,7 @@ public class GSSCredElement implements GSSCredentialSpi {
return "N/A"; return "N/A";
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
dispose(); dispose();
} }

@ -290,7 +290,7 @@ public class GSSNameElement implements GSSNameSpi {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
dispose(); dispose();
} }

@ -639,7 +639,7 @@ class NativeGSSContext implements GSSContextSpi {
return isInitiator; return isInitiator;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
dispose(); dispose();
} }

@ -136,7 +136,7 @@ abstract class CramMD5Base {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
clearPassword(); clearPassword();
} }

@ -195,7 +195,7 @@ final class PlainClient implements SaslClient {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
clearPassword(); clearPassword();
} }

@ -276,7 +276,7 @@ final class CardImpl extends Card {
+ ", protocol " + getProtocol() + ", state " + state; + ", protocol " + getProtocol() + ", state " + state;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (state == State.OK) { if (state == State.OK) {

@ -243,7 +243,7 @@ final class P11KeyStore extends KeyStoreSpi {
pc.setPassword(password); // this clones the password if not null pc.setPassword(password); // this clones the password if not null
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if (password != null) { if (password != null) {
Arrays.fill(password, ' '); Arrays.fill(password, ' ');

@ -1615,7 +1615,7 @@ public class PKCS11 {
* *
* @exception Throwable If finalization fails. * @exception Throwable If finalization fails.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
disconnect(); disconnect();
} }

@ -55,7 +55,7 @@ abstract class CKey implements Key, Length {
this.hCryptKey = hCryptKey; this.hCryptKey = hCryptKey;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
synchronized(this) { synchronized(this) {

@ -113,6 +113,7 @@ class SummaryTab extends Tab {
StringBuilder buf; StringBuilder buf;
@SuppressWarnings("deprecation")
synchronized Result formatSummary() { synchronized Result formatSummary() {
Result result = new Result(); Result result = new Result();
ProxyClient proxyClient = vmPanel.getProxyClient(); ProxyClient proxyClient = vmPanel.getProxyClient();

@ -112,7 +112,7 @@ final class ChunkInputStream extends InputStream {
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
super.finalize(); super.finalize();
close(); close();

@ -137,7 +137,7 @@ final class ChunksChannel implements ReadableByteChannel {
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
super.finalize(); super.finalize();
close(); close();

@ -134,7 +134,7 @@ final class RepositoryChunk {
} }
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
boolean destroy = false; boolean destroy = false;
synchronized (this) { synchronized (this) {

@ -148,7 +148,7 @@ public class DnsClient {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
close(); close();
} }

@ -120,7 +120,7 @@ public class RegistryContext implements Context, Referenceable {
reference = ctx.reference; reference = ctx.reference;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
close(); close();
} }
@ -596,7 +596,7 @@ class BindingEnumeration implements NamingEnumeration<Binding> {
nextName = 0; nextName = 0;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() { protected void finalize() {
ctx.close(); ctx.close();
} }

@ -162,7 +162,7 @@ abstract class GssKrb5Base extends AbstractSaslImpl {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
dispose(); dispose();
} }

@ -1219,7 +1219,7 @@ class ZipFileSystem extends FileSystem {
return zc.toString(name); return zc.toString(name);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("removal")
protected void finalize() throws IOException { protected void finalize() throws IOException {
close(); close();
} }