Add System#exit(), Runtime#exit() and Runtime#halt() to forbidden APIs

Closes #12596
This commit is contained in:
Daniel Mitterdorfer 2015-11-03 11:17:16 +01:00
parent d819930261
commit fea88bbc02
4 changed files with 25 additions and 3 deletions

View File

@ -100,3 +100,8 @@ org.apache.lucene.index.IndexReader#getCombinedCoreAndDeletesKey()
@defaultMessage this method needs special permission @defaultMessage this method needs special permission
java.lang.Thread#getAllStackTraces() java.lang.Thread#getAllStackTraces()
@defaultMessage Please do not terminate the application
java.lang.System#exit(int)
java.lang.Runtime#exit(int)
java.lang.Runtime#halt(int)

View File

@ -235,7 +235,7 @@ final class Bootstrap {
CliTool.ExitStatus status = bootstrapCLIParser.execute(args); CliTool.ExitStatus status = bootstrapCLIParser.execute(args);
if (CliTool.ExitStatus.OK != status) { if (CliTool.ExitStatus.OK != status) {
System.exit(status.status()); exit(status.status());
} }
INSTANCE = new Bootstrap(); INSTANCE = new Bootstrap();
@ -343,7 +343,12 @@ final class Bootstrap {
if (confFileSetting != null && confFileSetting.isEmpty() == false) { if (confFileSetting != null && confFileSetting.isEmpty() == false) {
ESLogger logger = Loggers.getLogger(Bootstrap.class); ESLogger logger = Loggers.getLogger(Bootstrap.class);
logger.info("{} is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed.", settingName); logger.info("{} is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed.", settingName);
System.exit(1); exit(1);
} }
} }
@SuppressForbidden(reason = "Allowed to exit explicitly in bootstrap phase")
private static void exit(int status) {
System.exit(status);
}
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.plugins;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.cli.CliTool; import org.elasticsearch.common.cli.CliTool;
import org.elasticsearch.common.cli.CliToolConfig; import org.elasticsearch.common.cli.CliToolConfig;
import org.elasticsearch.common.cli.Terminal; import org.elasticsearch.common.cli.Terminal;
@ -65,6 +66,11 @@ public class PluginManagerCliParser extends CliTool {
// configure but do not read the logging conf file // configure but do not read the logging conf file
LogConfigurator.configure(env.settings(), false); LogConfigurator.configure(env.settings(), false);
int status = new PluginManagerCliParser().execute(args).status(); int status = new PluginManagerCliParser().execute(args).status();
exit(status);
}
@SuppressForbidden(reason = "Allowed to exit explicitly from #main()")
private static void exit(int status) {
System.exit(status); System.exit(status);
} }

View File

@ -21,6 +21,7 @@ package org.elasticsearch.benchmark.search.geo;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoDistance;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.SizeValue;
@ -46,7 +47,7 @@ public class GeoDistanceSearchBenchmark {
ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
if (clusterHealthResponse.isTimedOut()) { if (clusterHealthResponse.isTimedOut()) {
System.err.println("Failed to wait for green status, bailing"); System.err.println("Failed to wait for green status, bailing");
System.exit(1); exit(1);
} }
final long NUM_DOCS = SizeValue.parseSizeValue("1m").singles(); final long NUM_DOCS = SizeValue.parseSizeValue("1m").singles();
@ -198,4 +199,9 @@ public class GeoDistanceSearchBenchmark {
.point(40.7143528, -74.0059731))) .point(40.7143528, -74.0059731)))
.execute().actionGet(); .execute().actionGet();
} }
@SuppressForbidden(reason = "Allowed to exit explicitly from #main()")
private static void exit(int status) {
System.exit(status);
}
} }