diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 442aefdbae5..a9c2648e4fc 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -62,6 +62,9 @@ Improvements previously treated as beginning a line-ending comment (Satoshi Kato and Masaru Hasegawa via Michael Sokolov) +* LUCENE-9109: Use StackWalker to implement TestSecurityManager's detection + of JVM exit (Uwe Schindler) + Bug fixes * LUCENE-8663: NRTCachingDirectory.slowFileExists may open a file while @@ -90,6 +93,9 @@ Improvements * LUCENE-9091: UnifiedHighlighter HTML escaping should only escape essentials (Nándor Mátravölgyi) +* LUCENE-9109: Backport some changes from master (except StackWalker) to improve + TestSecurityManager (Uwe Schindler) + Optimizations --------------------- (No changes) diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java index a164a9cf5c0..2eaccbe6d91 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java @@ -16,8 +16,9 @@ */ package org.apache.lucene.util; -import java.security.AccessController; -import java.security.PrivilegedAction; +import java.lang.StackWalker.StackFrame; +import java.util.Locale; +import java.util.function.Predicate; /** * A {@link SecurityManager} that prevents tests calling {@link System#exit(int)}. @@ -28,11 +29,14 @@ import java.security.PrivilegedAction; */ public final class TestSecurityManager extends SecurityManager { - static final String JUNIT4_TEST_RUNNER_PACKAGE = "com.carrotsearch.ant.tasks.junit4."; - static final String ECLIPSE_TEST_RUNNER_PACKAGE = "org.eclipse.jdt.internal.junit.runner."; - static final String IDEA_TEST_RUNNER_PACKAGE = "com.intellij.rt.execution.junit."; - static final String GRADLE_TEST_RUNNER_PACKAGE = "worker.org.gradle.process.internal.worker"; + private static final String JUNIT4_TEST_RUNNER_PACKAGE = "com.carrotsearch.ant.tasks.junit4."; + private static final String ECLIPSE_TEST_RUNNER_PACKAGE = "org.eclipse.jdt.internal.junit.runner."; + private static final String IDEA_TEST_RUNNER_PACKAGE = "com.intellij.rt.execution.junit."; + private static final String GRADLE_TEST_RUNNER_PACKAGE = "worker.org.gradle.process.internal.worker."; + private static final String SYSTEM_CLASS_NAME = System.class.getName(); + private static final String RUNTIME_CLASS_NAME = Runtime.class.getName(); + /** * Creates a new TestSecurityManager. This ctor is called on JVM startup, * when {@code -Djava.security.manager=org.apache.lucene.util.TestSecurityManager} @@ -41,7 +45,7 @@ public final class TestSecurityManager extends SecurityManager { public TestSecurityManager() { super(); } - + /** * {@inheritDoc} *
This method inspects the stack trace and checks who is calling
@@ -50,46 +54,27 @@ public final class TestSecurityManager extends SecurityManager {
*/
@Override
public void checkExit(final int status) {
- AccessController.doPrivileged(new PrivilegedAction