mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
38 lines
1.1 KiB
Java
38 lines
1.1 KiB
Java
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
|
|
public class ExampleSystemExit {
|
|
|
|
public static void main(String[] args) {
|
|
Action action = new Action();
|
|
try {
|
|
action.run();
|
|
} catch (Exception e) {
|
|
printUsageAndExit(e.getMessage(), 1);
|
|
}
|
|
System.exit(0); // COMPLIANT
|
|
}
|
|
|
|
static class Action {
|
|
public void run() {
|
|
try {
|
|
FileOutputStream fos = new FileOutputStream("output.txt");
|
|
fos.write("Hello, World!".getBytes());
|
|
fos.close();
|
|
System.exit(0); // $ Alert
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
System.exit(1); // $ Alert
|
|
} catch (Exception e) {
|
|
// re-throw the exception
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static void printUsageAndExit(final String message, final int exitCode) {
|
|
System.err.println("Usage: <example_cmd> <example_args> : " + message);
|
|
System.exit(exitCode); // COMPLIANT
|
|
}
|
|
}
|