On Fri, 8 Sep 2023 08:26:16 GMT, Matthias Baesken <mbaes...@openjdk.org> wrote:
> There are some remaining places in 'general' JDK code (= code not related to > e.g. a specific tool) getting properties like : > > osName = System.getProperty(os.name) > > https://github.com/openjdk/jdk/blob/master/src/java.management/share/classes/sun/management/VMManagementImpl.java#L225 > > https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/awt/FontConfiguration.java#L134 > > Those should be a PrivilegedAction . Hi Alan, seems the calling into the VMManagement methods does not work any more in recent JDK (in 8 it was still possible in a kind of hack-like way but I tried it with 21 and it does not work any more (or maybe with setting lots of flags?) ). import sun.management.VMManagement; import java.lang.management.*; import java.lang.reflect.*; import java.security.*; public class VMExample { static class MySm extends SecurityManager { public void checkPermission(Permission p) { // okay } @Override public void checkPropertyAccess(String key) { System.out.println("accessing " + key); // throw new SecurityException("accessing " + key); } } private static void printInfo() { try { // Get the current process id using a reflection hack RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); Field jvm = runtime.getClass().getDeclaredField("jvm"); jvm.setAccessible(true); System.out.println("Getting VMManagement object"); VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime); System.out.println("OS name:" + mgmt.getOsName()); } catch(Exception ex) { } } public static void main(String[] args) { //System.setSecurityManager(new SecurityManager()); System.setSecurityManager(new MySm()); System.out.println("Before printInfo ..."); printInfo(); } } So probably we could avoid changing VMManagementImpl.java because it is not needed any more at least in jdk-head . ------------- PR Comment: https://git.openjdk.org/jdk/pull/15629#issuecomment-1711480332