Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class JcToolsSecurityManagerTest {

@Test
// System.setSecurityManager throws UnsupportedOperationException in Java 18+
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_17})
@SuppressLogger(JcTools.class)
void newFixedSizeQueue_SunMiscProhibited() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.security.AccessControlException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;

// Security manager removed in Java 24
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11, JRE.JAVA_17, JRE.JAVA_21})
class SunMiscProhibitedSecurityManagerTest {

@Test
public void checkPackageAccess_ProhibitsSunMisc() {
SunMiscProhibitedSecurityManager sm = new SunMiscProhibitedSecurityManager();
assertThatThrownBy(() -> sm.checkPackageAccess("sun.misc"))
.isInstanceOf(SecurityException.class);
.isInstanceOf(AccessControlException.class)
Copy link
Contributor

@breedx-splk breedx-splk Sep 23, 2025

Choose a reason for hiding this comment

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

The javadoc for AccessControlException class say it was deprecated since 17 and is marked for removal, so we'll have to revisit eventually.

For other reviewers -- The AccessControlException is a more specific type of SecurityException.

Copy link
Member Author

Choose a reason for hiding this comment

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

ya, this PR effectively rolls back the change I made in #7679

and is more explicit about when and why it fails

.hasMessage(
"access denied (\"java.lang.RuntimePermission\" \"accessClassInPackage.sun.misc\")");
}

@Test
Expand All @@ -25,7 +32,9 @@ public void checkPackageAccess_ProhibitsSunMiscRuntimePermission() {

assertThatThrownBy(
() -> sm.checkPermission(new RuntimePermission("accessClassInPackage.sun.misc")))
.isInstanceOf(SecurityException.class);
.isInstanceOf(AccessControlException.class)
.hasMessage(
"access denied (\"java.lang.RuntimePermission\" \"accessClassInPackage.sun.misc\")");
}

@Test
Expand Down
Loading