RFR [9] 8040837: Avoid provoking NFEs when initializing InetAddrCachePolicy

Michael McMahon michael.x.mcmahon at oracle.com
Fri Apr 18 16:27:47 UTC 2014


I think it would be an improvement to combine these doPrivileged() blocks
as suggested, though your patch needs work Bernd. For instance,
the multi-catch doesn't work. Also the PrivilegedAction<> type is wrong.

If someone wants to update it, then we can use that. Otherwise, we'll
go with the original suggested change.

Thanks
Michael

On 17/04/14 21:28, Bernd Eckenfels wrote:
> Am Thu, 17 Apr 2014 21:50:23 +0200
> schrieb Bernd Eckenfels <bernd-2014 at eckenfels.net>:
>
>> Hello,
>>
>> I would propose to use Integer.valueOf(tmp) instead, but looking at
>> the context I think it is even better to skip this and the following
>> null check with Integer.parseInt().
> This is even shorter and it reduces the privileged actions invocations:
>
>         Integer tmp = java.security.AccessController.doPrivileged (
>         new PrivilegedAction<String>() {
>             public String run() {
>                 try {
>                     String tmpString = Security.getProperty(cachePolicyProp);
> 		   if (tmpString != null) return Integer.valueOf(tmpString);
>                 } catch (NumberFormatException | IllegalArgumentException ignored) { }
>
>                 try {
>                     return Integer.getInteger(cachePolicyPropFallback);
>                 } catch (NumberFormatException | IllegalArgumentException ignored) { }
>
>                 return null;
>             }
>         });
>
>          if (tmp != null) {
>              cachePolicy = tmp.intValue();
>              if (cachePolicy < 0) {
>                  cachePolicy = FOREVER;
>              }
>              propertySet = true;
>          } else {
>              /* No properties defined for positive caching. If there is no
>               * security manager then use the default positive cache value. */
>              if (System.getSecurityManager() == null) {
>                  cachePolicy = DEFAULT_POSITIVE;
>              }
>          }
>
> NB: this will



More information about the net-dev mailing list