6268216: Boolean.getBoolean() throws SecurityException

Reviewed-by: mduigou
This commit is contained in:
Joe Darcy 2011-09-20 18:33:25 -07:00
parent b9c11d661e
commit 17af9b241a
3 changed files with 20 additions and 11 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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}. * @param s the string to be converted to a {@code Boolean}.
*/ */
public Boolean(String s) { 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 * @since 1.5
*/ */
public static boolean parseBoolean(String s) { 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. * @return the {@code Boolean} value represented by the string.
*/ */
public static Boolean valueOf(String s) { 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. * @param name the system property name.
* @return the {@code boolean} value of the system property. * @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)
* @see java.lang.System#getProperty(java.lang.String, java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
*/ */
public static boolean getBoolean(String name) { public static boolean getBoolean(String name) {
boolean result = false; boolean result = false;
try { try {
result = toBoolean(System.getProperty(name)); result = parseBoolean(System.getProperty(name));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException | NullPointerException e) {
} catch (NullPointerException e) {
} }
return result; return result;
} }
@ -275,8 +276,4 @@ public final class Boolean implements java.io.Serializable,
public static int compare(boolean x, boolean y) { public static int compare(boolean x, boolean y) {
return (x == y) ? 0 : (x ? 1 : -1); return (x == y) ? 0 : (x ? 1 : -1);
} }
private static boolean toBoolean(String name) {
return ((name != null) && name.equalsIgnoreCase("true"));
}
} }

View File

@ -797,6 +797,8 @@ public final class Integer extends Number implements Comparable<Integer> {
* *
* @param nm property name. * @param nm property name.
* @return the {@code Integer} value of the property. * @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)
* @see java.lang.System#getProperty(java.lang.String, 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 nm property name.
* @param val default value. * @param val default value.
* @return the {@code Integer} value of the property. * @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)
* @see java.lang.System#getProperty(java.lang.String, 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 nm property name.
* @param val default value. * @param val default value.
* @return the {@code Integer} value of the property. * @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)
* @see System#getProperty(java.lang.String, java.lang.String) * @see System#getProperty(java.lang.String, java.lang.String)
*/ */

View File

@ -827,6 +827,8 @@ public final class Long extends Number implements Comparable<Long> {
* *
* @param nm property name. * @param nm property name.
* @return the {@code Long} value of the property. * @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)
* @see java.lang.System#getProperty(java.lang.String, 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 nm property name.
* @param val default value. * @param val default value.
* @return the {@code Long} value of the property. * @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)
* @see java.lang.System#getProperty(java.lang.String, 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 nm property name.
* @param val default value. * @param val default value.
* @return the {@code Long} value of the property. * @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)
* @see System#getProperty(java.lang.String, java.lang.String) * @see System#getProperty(java.lang.String, java.lang.String)
*/ */