Index: lucene/common-build.xml =================================================================== --- lucene/common-build.xml (revision 1380239) +++ lucene/common-build.xml (working copy) @@ -799,7 +799,7 @@ - + Index: lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java (revision 0) +++ lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java (working copy) @@ -0,0 +1,61 @@ +package org.apache.lucene.util; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A {@link SecurityManager} that prevents {@link System#exit(int)}. + * All other checks are handled by the default {@code SecurityManager}. + *

+ * Use this with {@code -Djava.security.manager=org.apache.lucene.util.TestSecurityManager}. + */ +public final class TestSecurityManager extends SecurityManager { + + public TestSecurityManager() { + super(); + } + + @Override + public void checkExit(int status) { + final String systemClassName = System.class.getName(), + runtimeClassName = Runtime.class.getName(); + boolean exitMethodHit = false; + for (final StackTraceElement se : Thread.currentThread().getStackTrace()) { + if ( + "exit".equals(se.getMethodName()) && + (systemClassName.equals(se.getClassName()) || runtimeClassName.equals(se.getClassName())) + ) { + exitMethodHit = true; + continue; + } + + if (exitMethodHit) { + if (se.getClassName().startsWith("com.carrotsearch.ant.tasks.junit4.")) { + // this exit point is allowed, delegate to super (as required by SecurityManager spec) + super.checkExit(status); + return; + } else { + // anything else is not allowed. + break; + } + } + } + + throw new SecurityException("System.exit() calls are not allowed because they terminate the test runner's JVM."); + } + +} Index: lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java (revision 0) +++ lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java (working copy) Property changes on: lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property