Files
codeql/java/ql/test/query-tests/CallsToSystemExit/ExampleRuntimeHalt.java
2025-08-11 09:24:01 +02:00

26 lines
712 B
Java

import java.io.FileOutputStream;
import java.io.IOException;
public class ExampleRuntimeHalt {
public static void main(String[] args) {
Action action = new Action();
action.run();
Runtime.getRuntime().halt(0); // COMPLIANT
}
static class Action {
public void run() {
try {
FileOutputStream fos = new FileOutputStream("output.txt");
fos.write("Hello, World!".getBytes());
fos.close();
Runtime.getRuntime().halt(0); // $ Alert
} catch (IOException e) {
e.printStackTrace();
Runtime.getRuntime().halt(1); // $ Alert
}
}
}
}