RFR: 8048199: Replace anonymous inner classes with lambdas, where applicable, in JNDI
ccleary at openjdk.java.net
Fri Apr 9 15:51:36 UTC 2021
On Fri, 9 Apr 2021 13:46:46 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> ### Description
>> This fix is part of a previous effort to both cleanup/modernise JNDI code, the details of which can be seen in [JDK-8048091](https://bugs.openjdk.java.net/browse/JDK-8048091). A number JNDI methods under `java.naming` use Anonymous Inner Classes in cases where only a single object unique to the requirements of the method is used. The issues these occurrences of AICs cause are highlighted below.
>> - AICs, in the cases concerned with this fix, are used where only one operation is required. While AICs can be useful for more complex implementations (using interfaces, multiple methods needed, local fields etc.), Lambdas are better suited here as they result in a more readable and concise solution.
>> ### Fixes
>> - Where applicable, occurrences of AICs were replaced with lambdas to address the issues above resulting primarily in more readable/concise code.
> src/java.naming/share/classes/com/sun/jndi/ldap/LdapPoolManager.java line 413:
>> 411: return AccessController.doPrivileged(
>> 412: (PrivilegedAction<Long>) () -> Long.getLong(propName, defVal).longValue()
>> 413: );
> And GetIntegerAction here. Though it only supports an int value.
Thanks for the suggestion Roger, I think the `privilegedGetProperty(prop, default)` for the `getProperty()` method looks great.
WRT to using it for `getInt()` and `getLong()`, I think its reasonable to use other means for these methods in the interest of consistency due to, as you pointed out, only `int` being supported. Would you think? Or would it be better to use the same means in all 3 methods?
More information about the core-libs-dev