6268216: Boolean.getBoolean() throws SecurityException
Reviewed-by: mduigou
This commit is contained in:
parent
b9c11d661e
commit
17af9b241a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -101,7 +101,7 @@ public final class Boolean implements java.io.Serializable,
|
||||
* @param s the string to be converted to a {@code Boolean}.
|
||||
*/
|
||||
public Boolean(String s) {
|
||||
this(toBoolean(s));
|
||||
this(parseBoolean(s));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +118,7 @@ public final class Boolean implements java.io.Serializable,
|
||||
* @since 1.5
|
||||
*/
|
||||
public static boolean parseBoolean(String s) {
|
||||
return toBoolean(s);
|
||||
return ((s != null) && s.equalsIgnoreCase("true"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,7 +159,7 @@ public final class Boolean implements java.io.Serializable,
|
||||
* @return the {@code Boolean} value represented by the string.
|
||||
*/
|
||||
public static Boolean valueOf(String s) {
|
||||
return toBoolean(s) ? TRUE : FALSE;
|
||||
return parseBoolean(s) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -229,15 +229,16 @@ public final class Boolean implements java.io.Serializable,
|
||||
*
|
||||
* @param name the system property name.
|
||||
* @return the {@code boolean} value of the system property.
|
||||
* @throws SecurityException for the same reasons as
|
||||
* {@link System#getProperty(String) System.getProperty}
|
||||
* @see java.lang.System#getProperty(java.lang.String)
|
||||
* @see java.lang.System#getProperty(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public static boolean getBoolean(String name) {
|
||||
boolean result = false;
|
||||
try {
|
||||
result = toBoolean(System.getProperty(name));
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (NullPointerException e) {
|
||||
result = parseBoolean(System.getProperty(name));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -275,8 +276,4 @@ public final class Boolean implements java.io.Serializable,
|
||||
public static int compare(boolean x, boolean y) {
|
||||
return (x == y) ? 0 : (x ? 1 : -1);
|
||||
}
|
||||
|
||||
private static boolean toBoolean(String name) {
|
||||
return ((name != null) && name.equalsIgnoreCase("true"));
|
||||
}
|
||||
}
|
||||
|
@ -797,6 +797,8 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||
*
|
||||
* @param nm property name.
|
||||
* @return the {@code Integer} value of the property.
|
||||
* @throws SecurityException for the same reasons as
|
||||
* {@link System#getProperty(String) System.getProperty}
|
||||
* @see java.lang.System#getProperty(java.lang.String)
|
||||
* @see java.lang.System#getProperty(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@ -841,6 +843,8 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||
* @param nm property name.
|
||||
* @param val default value.
|
||||
* @return the {@code Integer} value of the property.
|
||||
* @throws SecurityException for the same reasons as
|
||||
* {@link System#getProperty(String) System.getProperty}
|
||||
* @see java.lang.System#getProperty(java.lang.String)
|
||||
* @see java.lang.System#getProperty(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@ -881,6 +885,8 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||
* @param nm property name.
|
||||
* @param val default value.
|
||||
* @return the {@code Integer} value of the property.
|
||||
* @throws SecurityException for the same reasons as
|
||||
* {@link System#getProperty(String) System.getProperty}
|
||||
* @see System#getProperty(java.lang.String)
|
||||
* @see System#getProperty(java.lang.String, java.lang.String)
|
||||
*/
|
||||
|
@ -827,6 +827,8 @@ public final class Long extends Number implements Comparable<Long> {
|
||||
*
|
||||
* @param nm property name.
|
||||
* @return the {@code Long} value of the property.
|
||||
* @throws SecurityException for the same reasons as
|
||||
* {@link System#getProperty(String) System.getProperty}
|
||||
* @see java.lang.System#getProperty(java.lang.String)
|
||||
* @see java.lang.System#getProperty(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@ -870,6 +872,8 @@ public final class Long extends Number implements Comparable<Long> {
|
||||
* @param nm property name.
|
||||
* @param val default value.
|
||||
* @return the {@code Long} value of the property.
|
||||
* @throws SecurityException for the same reasons as
|
||||
* {@link System#getProperty(String) System.getProperty}
|
||||
* @see java.lang.System#getProperty(java.lang.String)
|
||||
* @see java.lang.System#getProperty(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@ -917,6 +921,8 @@ public final class Long extends Number implements Comparable<Long> {
|
||||
* @param nm property name.
|
||||
* @param val default value.
|
||||
* @return the {@code Long} value of the property.
|
||||
* @throws SecurityException for the same reasons as
|
||||
* {@link System#getProperty(String) System.getProperty}
|
||||
* @see System#getProperty(java.lang.String)
|
||||
* @see System#getProperty(java.lang.String, java.lang.String)
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user