Skip to content

Commit

Permalink
8286045: Use ForceGC for cleaner test cases
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken, yan
Backport-of: 7eb15593e18a923bbc18c8d596cff87d87019640
  • Loading branch information
gnu-andrew committed Mar 29, 2024
1 parent ba77d0b commit d2df108
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ com/sun/security/sasl/gsskerb/ConfSecurityLayer.java 8039280 generic-
com/sun/security/sasl/gsskerb/NoSecurityLayer.java 8039280 generic-all
javax/security/auth/kerberos/KerberosHashEqualsTest.java 8039280 generic-all
javax/security/auth/kerberos/KerberosTixDateTest.java 8039280 generic-all
javax/security/auth/callback/PasswordCallback/CheckCleanerBound.java 8286045 generic-all
sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 generic-all
sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all
sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,31 @@
* @test
* @bug 8284910
* @summary Check that the cleaner is not bound to the PasswordCallback object
* @library /test/lib/
* @build jdk.test.lib.util.ForceGC
* @run main/othervm CheckCleanerBound
*/

import javax.security.auth.callback.PasswordCallback;
import java.util.WeakHashMap;
import java.lang.ref.WeakReference;
import jdk.test.lib.util.ForceGC;

public final class CheckCleanerBound {
private final static WeakHashMap<PasswordCallback, ?> weakHashMap =
new WeakHashMap<>();

public static void main(String[] args) throws Exception {
// Create an object
PasswordCallback passwordCallback =
new PasswordCallback("Password: ", false);
passwordCallback.setPassword("ThisIsAPassword".toCharArray());

weakHashMap.put(passwordCallback, null);
WeakReference<PasswordCallback> weakRef =
new WeakReference<>(passwordCallback);
passwordCallback = null;

// Check if the PasswordCallback object could be collected.
// Wait to trigger the cleanup.
for (int i = 0; i < 10 && weakHashMap.size() != 0; i++) {
System.gc();
Thread.sleep(100);
}

// Check if the object has been collected. The collection will not
// happen if the cleaner implementation in PasswordCallback is bound
// to the PasswordCallback object.
if (weakHashMap.size() > 0) {
if (!ForceGC.wait(() -> weakRef.refersTo(null))) {
throw new RuntimeException(
"PasswordCallback object is not released");
}
Expand Down

1 comment on commit d2df108

@openjdk-notifier
Copy link

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.