src/share/classes/sun/net/InetAddressCachePolicy.java
Print this page
rev 9767 : 8040837: Avoid provoking NFEs when initializing InetAddrCachePolicy
Reviewed-by: mduigou
Contributed-by: bernd-2014@eckenfels.net, claes.redestad@oracle.com
@@ -82,32 +82,35 @@
/*
* Initialize
*/
static {
- Integer tmp = null;
+ Integer tmp = java.security.AccessController.doPrivileged(
+ new PrivilegedAction<Integer>() {
+ public Integer run() {
try {
- tmp = new Integer(
- java.security.AccessController.doPrivileged (
- new PrivilegedAction<String>() {
- public String run() {
- return Security.getProperty(cachePolicyProp);
- }
- }));
- } catch (NumberFormatException e) {
- // ignore
+ String tmpString = Security.getProperty(cachePolicyProp);
+ if (tmpString != null) {
+ return Integer.valueOf(tmpString);
}
- if (tmp != null) {
- cachePolicy = tmp.intValue();
- if (cachePolicy < 0) {
- cachePolicy = FOREVER;
+ } catch (NumberFormatException ignored) {
+ // Ignore
}
- propertySet = true;
- } else {
- tmp = java.security.AccessController.doPrivileged
- (new sun.security.action.GetIntegerAction(cachePolicyPropFallback));
+
+ try {
+ String tmpString = Security.getProperty(cachePolicyPropFallback);
+ if (tmpString != null) {
+ return Integer.decode(tmpString);
+ }
+ } catch (NumberFormatException ignored) {
+ // Ignore
+ }
+ return null;
+ }
+ });
+
if (tmp != null) {
cachePolicy = tmp.intValue();
if (cachePolicy < 0) {
cachePolicy = FOREVER;
}
@@ -118,42 +121,42 @@
*/
if (System.getSecurityManager() == null) {
cachePolicy = DEFAULT_POSITIVE;
}
}
+ tmp = java.security.AccessController.doPrivileged (
+ new PrivilegedAction<Integer>() {
+ public Integer run() {
+ try {
+ String tmpString = Security.getProperty(negativeCachePolicyProp);
+ if (tmpString != null) {
+ return Integer.valueOf(tmpString);
+ }
+ } catch (NumberFormatException ignored) {
+ // Ignore
}
try {
- tmp = new Integer(
- java.security.AccessController.doPrivileged (
- new PrivilegedAction<String>() {
- public String run() {
- return Security.getProperty(negativeCachePolicyProp);
- }
- }));
- } catch (NumberFormatException e) {
- // ignore
+ String tmpString = Security.getProperty(negativeCachePolicyPropFallback);
+ if (tmpString != null) {
+ return Integer.decode(tmpString);
}
-
- if (tmp != null) {
- negativeCachePolicy = tmp.intValue();
- if (negativeCachePolicy < 0) {
- negativeCachePolicy = FOREVER;
+ } catch (NumberFormatException ignored) {
+ // Ignore
}
- propertyNegativeSet = true;
- } else {
- tmp = java.security.AccessController.doPrivileged
- (new sun.security.action.GetIntegerAction(negativeCachePolicyPropFallback));
+ return null;
+ }
+ });
+
if (tmp != null) {
negativeCachePolicy = tmp.intValue();
if (negativeCachePolicy < 0) {
negativeCachePolicy = FOREVER;
}
propertyNegativeSet = true;
}
}
- }
public static synchronized int get() {
return cachePolicy;
}