diff --git a/LUCENE-4352.patch b/LUCENE-4352.patch new file mode 100644 index 0000000..c195750 --- /dev/null +++ b/LUCENE-4352.patch @@ -0,0 +1,13 @@ +diff --git a/lucene/common-build.xml b/lucene/common-build.xml +index 01a95a0..2c9b8b3 100644 +--- a/lucene/common-build.xml ++++ b/lucene/common-build.xml +@@ -799,7 +799,7 @@ + + + +- ++ + + + diff --git a/lucene/common-build.xml b/lucene/common-build.xml index 01a95a0..2c9b8b3 100644 --- a/lucene/common-build.xml +++ b/lucene/common-build.xml @@ -799,7 +799,7 @@ - + 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 new file mode 100644 index 0000000..01d5c75 --- /dev/null +++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestSecurityManager.java @@ -0,0 +1,59 @@ +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)}. + * @lucene.internal + */ +public final class TestSecurityManager extends SecurityManager { + + public TestSecurityManager() { + super(); + // just paranoid: + if (System.getProperty("java.security.policy") == null) + throw new SecurityException("For text-framework to work correctly, you must use the tests.policy file with -Djava.security.policy"); + } + + @Override + public void checkExit(int status) { + final String systemClassName = System.class.getName(); + final String runtimeClassName = Runtime.class.getName(); + boolean exitMethodHit = false; + for (StackTraceElement se : Thread.currentThread().getStackTrace()) { + if (se.getMethodName().equals("exit") && + (se.getClassName().equals(systemClassName) || se.getClassName().equals(runtimeClassName))) { + exitMethodHit = true; + continue; + } + + if (exitMethodHit) { + if (se.getClassName().startsWith("com.carrotsearch.ant.tasks.junit4.")) { + // this exit point is allowed. + 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."); + } +}