defensive-coding-guide/modules/ROOT/examples/Java-SecurityManager-Privileged.adoc
2022-01-13 20:42:40 +01:00

15 lines
393 B
Text

// This is expected to fail.
try {
System.out.println(System.getProperty("user.home"));
} catch (SecurityException e) {
e.printStackTrace(System.err);
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
// This should work.
System.out.println(System.getProperty("user.home"));
return null;
}
});