Skip to content
Permalink
Browse files
8284368: Remove finalizer method in jdk.crypto.cryptoki
Reviewed-by: valeriep
  • Loading branch information
XueleiFan committed Apr 6, 2022
1 parent 8e4fab0 commit 77388eaf2595f5785bb0945ccecf84c4916031e7
Showing 2 changed files with 7 additions and 20 deletions.
@@ -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 @@ private static class PasswordCallbackHandler implements CallbackHandler {
private PasswordCallbackHandler(char[] password) {
if (password != null) {
this.password = password.clone();
Cleaner.create().register(this,
() -> Arrays.fill(this.password, ' '));
}
}

@@ -242,14 +245,6 @@ public void handle(Callback[] callbacks)
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 static void loadNative() {
// 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 String toString() {
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 {

1 comment on commit 77388ea

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 77388ea Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.