8284368: Remove finalizer method in jdk.crypto.cryptoki
Reviewed-by: valeriep
This commit is contained in:
parent
8e4fab0c89
commit
77388eaf25
@ -25,6 +25,7 @@
|
||||
|
||||
package sun.security.pkcs11;
|
||||
|
||||
import java.lang.ref.Cleaner;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import java.io.InputStream;
|
||||
@ -231,6 +232,8 @@ final class P11KeyStore extends KeyStoreSpi {
|
||||
private PasswordCallbackHandler(char[] password) {
|
||||
if (password != null) {
|
||||
this.password = password.clone();
|
||||
Cleaner.create().register(this,
|
||||
() -> Arrays.fill(this.password, ' '));
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,14 +245,6 @@ final class P11KeyStore extends KeyStoreSpi {
|
||||
PasswordCallback pc = (PasswordCallback)callbacks[0];
|
||||
pc.setPassword(password); // this clones the password if not null
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
protected void finalize() throws Throwable {
|
||||
if (password != null) {
|
||||
Arrays.fill(password, ' ');
|
||||
}
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,6 +47,7 @@
|
||||
|
||||
package sun.security.pkcs11.wrapper;
|
||||
|
||||
import java.lang.ref.Cleaner;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
@ -161,6 +162,9 @@ public class PKCS11 {
|
||||
// give up; just use what is returned by connect()
|
||||
}
|
||||
}
|
||||
|
||||
// Calls disconnect() to cleanup the native part of the wrapper.
|
||||
Cleaner.create().register(this, this::disconnect);
|
||||
}
|
||||
|
||||
public CK_VERSION getVersion() {
|
||||
@ -1657,18 +1661,6 @@ public class PKCS11 {
|
||||
return "Module name: " + pkcs11ModulePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls disconnect() to cleanup the native part of the wrapper. Once this
|
||||
* method is called, this object cannot be used any longer. Any subsequent
|
||||
* call to a C_* method will result in a runtime exception.
|
||||
*
|
||||
* @exception Throwable If finalization fails.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
protected void finalize() throws Throwable {
|
||||
disconnect();
|
||||
}
|
||||
|
||||
// PKCS11 subclass that has all methods synchronized and delegating to the
|
||||
// parent. Used for tokens that only support single threaded access
|
||||
static class SynchronizedPKCS11 extends PKCS11 {
|
||||
|
Loading…
Reference in New Issue
Block a user