Ignore:
Timestamp:
2018-04-19T20:37:16+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16204 - Allow to start and close JOSM in WebStart sandbox mode (where every external access is denied). This was very useful to reproduce some very tricky bugs that occured in real life but were almost impossible to diagnose.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r13597 r13647  
    887887     */
    888888    public static File getJosmTempDir() {
    889         String tmpDir = System.getProperty("java.io.tmpdir");
     889        String tmpDir = getSystemProperty("java.io.tmpdir");
    890890        if (tmpDir == null) {
    891891            return null;
     
    12681268
    12691269    /**
     1270     * Gets the value of the specified environment variable.
     1271     * An environment variable is a system-dependent external named value.
     1272     * @param name name the name of the environment variable
     1273     * @return the string value of the variable;
     1274     *         {@code null} if the variable is not defined in the system environment or if a security exception occurs.
     1275     * @see System#getenv(String)
     1276     * @since 13647
     1277     */
     1278    public static String getSystemEnv(String name) {
     1279        try {
     1280            return System.getenv(name);
     1281        } catch (SecurityException e) {
     1282            Logging.log(Logging.LEVEL_ERROR, "Unable to get system env", e);
     1283            return null;
     1284        }
     1285    }
     1286
     1287    /**
     1288     * Gets the system property indicated by the specified key.
     1289     * @param key the name of the system property.
     1290     * @return the string value of the system property;
     1291     *         {@code null} if there is no property with that key or if a security exception occurs.
     1292     * @see System#getProperty(String)
     1293     * @since 13647
     1294     */
     1295    public static String getSystemProperty(String key) {
     1296        try {
     1297            return System.getProperty(key);
     1298        } catch (SecurityException e) {
     1299            Logging.log(Logging.LEVEL_ERROR, "Unable to get system property", e);
     1300            return null;
     1301        }
     1302    }
     1303
     1304    /**
    12701305     * Updates a given system property.
    12711306     * @param key The property key
     
    12761311    public static String updateSystemProperty(String key, String value) {
    12771312        if (value != null) {
    1278             String old = System.setProperty(key, value);
    1279             if (Logging.isDebugEnabled() && !value.equals(old)) {
    1280                 if (!key.toLowerCase(Locale.ENGLISH).contains("password")) {
    1281                     Logging.debug("System property '" + key + "' set to '" + value + "'. Old value was '" + old + '\'');
    1282                 } else {
    1283                     Logging.debug("System property '" + key + "' changed.");
     1313            try {
     1314                String old = System.setProperty(key, value);
     1315                if (Logging.isDebugEnabled() && !value.equals(old)) {
     1316                    if (!key.toLowerCase(Locale.ENGLISH).contains("password")) {
     1317                        Logging.debug("System property '" + key + "' set to '" + value + "'. Old value was '" + old + '\'');
     1318                    } else {
     1319                        Logging.debug("System property '" + key + "' changed.");
     1320                    }
    12841321                }
    1285             }
    1286             return old;
     1322                return old;
     1323            } catch (SecurityException e) {
     1324                // Don't call Logging class, it may not be fully initialized yet
     1325                System.err.println("Unable to update system property: " + e.getMessage());
     1326            }
    12871327        }
    12881328        return null;
     
    15921632     */
    15931633    public static int getJavaVersion() {
    1594         String version = System.getProperty("java.version");
     1634        String version = getSystemProperty("java.version");
    15951635        if (version.startsWith("1.")) {
    15961636            version = version.substring(2);
     
    16131653     */
    16141654    public static int getJavaUpdate() {
    1615         String version = System.getProperty("java.version");
     1655        String version = getSystemProperty("java.version");
    16161656        if (version.startsWith("1.")) {
    16171657            version = version.substring(2);
     
    16431683     */
    16441684    public static int getJavaBuild() {
    1645         String version = System.getProperty("java.runtime.version");
     1685        String version = getSystemProperty("java.runtime.version");
    16461686        int bPos = version.indexOf('b');
    16471687        int pPos = version.indexOf('+');
     
    17571797        try {
    17581798            return new ScriptEngineManager(null).getEngineByName("JavaScript");
    1759         } catch (SecurityException e) {
    1760             Logging.error(e);
     1799        } catch (SecurityException | ExceptionInInitializerError e) {
     1800            Logging.log(Logging.LEVEL_ERROR, "Unable to get JavaScript engine", e);
    17611801            return null;
    17621802        }
     
    17891829                            FileTime jarTime = Files.readAttributes(jarFile, BasicFileAttributes.class).lastModifiedTime();
    17901830                            // Copy it to temp directory (hopefully free of exclamation mark) if needed (missing or older jar)
    1791                             Path jarCopy = Paths.get(System.getProperty("java.io.tmpdir")).resolve(filename);
     1831                            Path jarCopy = Paths.get(getSystemProperty("java.io.tmpdir")).resolve(filename);
    17921832                            if (!jarCopy.toFile().exists() ||
    17931833                                    Files.readAttributes(jarCopy, BasicFileAttributes.class).lastModifiedTime().compareTo(jarTime) < 0) {
Note: See TracChangeset for help on using the changeset viewer.