RFR: 8048199: Replace anonymous inner classes with lambdas, where applicable, in JNDI

Conor Cleary ccleary at openjdk.java.net
Fri Apr 9 13:55:26 UTC 2021


On Fri, 9 Apr 2021 13:45:03 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> src/java.naming/share/classes/com/sun/jndi/ldap/LdapPoolManager.java line 401:
>> 
>>> 399:         return AccessController.doPrivileged(
>>> 400:                 (PrivilegedAction<String>) () -> System.getProperty(propName, defVal)
>>> 401:         );
>> 
>> If you want to avoid the cast then you could create the PrivilegedAction explicitly, e.g.
>> 
>> PrivilegedAction<String> pa = () -> System.getProperty(propName, defVal);
>> return AccessController.doPrivileged(pa);
>
> An alternative here would be to use sun.security.action.privilegedGetProperty(prop, default).
> The package is already exported from java.base to java.desktop, etc.

That is a very neat alternative yes. Approaching the problem like that especially improves the readability [JdkLDAP.java](https://github.com/openjdk/jdk/pull/3416/files#diff-bf4c67da93cf2b9196508db2d57f7e01bc884f2268f5bfd43a9f01dfd55e4955) in my opinion. 
I don't think casting has any major performance hits for these fixes, so is your suggestion mostly for readability's sake?

-------------

PR: https://git.openjdk.java.net/jdk/pull/3416



More information about the security-dev mailing list