mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8316964: Security tools should not call System.exit
Reviewed-by: valeriep
This commit is contained in:
parent
1f2a80b78a
commit
1ddf826aea
8 changed files with 370 additions and 220 deletions
|
@ -405,26 +405,38 @@ public final class Main {
|
|||
collator.setStrength(Collator.PRIMARY);
|
||||
}
|
||||
|
||||
private Main() { }
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Main kt = new Main();
|
||||
kt.run(args, System.out);
|
||||
int exitCode = kt.run(args, System.out);
|
||||
if (exitCode != 0) {
|
||||
System.exit(exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
private void run(String[] args, PrintStream out) throws Exception {
|
||||
private static class ExitException extends RuntimeException {
|
||||
@java.io.Serial
|
||||
static final long serialVersionUID = 0L;
|
||||
private final int errorCode;
|
||||
public ExitException(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
public int run(String[] args, PrintStream out) throws Exception {
|
||||
try {
|
||||
args = parseArgs(args);
|
||||
parseArgs(args);
|
||||
if (command != null) {
|
||||
doCommands(out);
|
||||
}
|
||||
} catch (ExitException ee) {
|
||||
return ee.errorCode;
|
||||
} catch (Exception e) {
|
||||
System.out.println(rb.getString("keytool.error.") + e);
|
||||
if (verbose) {
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
if (!debug) {
|
||||
System.exit(1);
|
||||
return 1;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
@ -441,6 +453,7 @@ public final class Main {
|
|||
ksStream.close();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5247,7 +5260,7 @@ public final class Main {
|
|||
if (debug) {
|
||||
throw new RuntimeException("NO BIG ERROR, SORRY");
|
||||
} else {
|
||||
System.exit(1);
|
||||
throw new ExitException(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue