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

Reviewed-by: rriggs, dfuchs, aefimov, chegar
This commit is contained in:
Conor Cleary 2021-04-15 14:08:27 +00:00 committed by Aleksei Efimov
parent 6293299dd3
commit 4e90d74000
5 changed files with 36 additions and 84 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -59,12 +59,8 @@ final class LdapBindingEnumeration
if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) {
// serialized object or object reference
try {
obj = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws NamingException {
return Obj.decodeObject(attrs);
}
}, acc);
PrivilegedExceptionAction<Object> pa = () -> Obj.decodeObject(attrs);
obj = AccessController.doPrivileged(pa, acc);
} catch (PrivilegedActionException e) {
throw (NamingException)e.getException();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -395,47 +395,18 @@ public final class LdapPoolManager {
}
}
private static final String getProperty(final String propName,
final String defVal) {
return AccessController.doPrivileged(
new PrivilegedAction<String>() {
public String run() {
try {
return System.getProperty(propName, defVal);
} catch (SecurityException e) {
return defVal;
}
}
});
private static final String getProperty(final String propName, final String defVal) {
PrivilegedAction<String> pa = () -> System.getProperty(propName, defVal);
return AccessController.doPrivileged(pa);
}
private static final int getInteger(final String propName,
final int defVal) {
Integer val = AccessController.doPrivileged(
new PrivilegedAction<Integer>() {
public Integer run() {
try {
return Integer.getInteger(propName, defVal);
} catch (SecurityException e) {
return defVal;
}
}
});
return val.intValue();
private static final int getInteger(final String propName, final int defVal) {
PrivilegedAction<Integer> pa = () -> Integer.getInteger(propName, defVal);
return AccessController.doPrivileged(pa);
}
private static final long getLong(final String propName,
final long defVal) {
Long val = AccessController.doPrivileged(
new PrivilegedAction<Long>() {
public Long run() {
try {
return Long.getLong(propName, defVal);
} catch (SecurityException e) {
return defVal;
}
}
});
return val.longValue();
private static final long getLong(final String propName, final long defVal) {
PrivilegedAction<Long> pa = () -> Long.getLong(propName, defVal);
return AccessController.doPrivileged(pa);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -119,12 +119,8 @@ final class LdapSearchEnumeration
// Entry contains Java-object attributes (ser/ref object)
// serialized object or object reference
try {
obj = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws NamingException {
return Obj.decodeObject(attrs);
}
}, acc);
PrivilegedExceptionAction<Object> pea = () -> Obj.decodeObject(attrs);
obj = AccessController.doPrivileged(pea, acc);
} catch (PrivilegedActionException e) {
throw (NamingException)e.getException();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -220,23 +220,13 @@ public class StartTlsRequest implements ExtendedRequest {
* Acquire the class loader associated with this thread.
*/
private final ClassLoader getContextClassLoader() {
return AccessController.doPrivileged(
new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
}
);
PrivilegedAction<ClassLoader> pa = Thread.currentThread()::getContextClassLoader;
return AccessController.doPrivileged(pa);
}
private static final boolean privilegedHasNext(final Iterator<StartTlsResponse> iter) {
Boolean answer = AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
public Boolean run() {
return Boolean.valueOf(iter.hasNext());
}
});
return answer.booleanValue();
PrivilegedAction<Boolean> pa = iter::hasNext;
return AccessController.doPrivileged(pa);
}
private static final long serialVersionUID = 4441679576360753397L;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -73,21 +73,20 @@ public final class JdkLDAP extends Provider {
super("JdkLDAP", PROVIDER_VER, "JdkLDAP Provider (implements LDAP CertStore)");
final Provider p = this;
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
HashMap<String, String> attrs = new HashMap<>(2);
attrs.put("LDAPSchema", "RFC2587");
attrs.put("ImplementedIn", "Software");
PrivilegedAction<Void> pa = () -> {
HashMap<String, String> attrs = new HashMap<>(2);
attrs.put("LDAPSchema", "RFC2587");
attrs.put("ImplementedIn", "Software");
/*
* CertStore
* attrs: LDAPSchema, ImplementedIn
*/
putService(new ProviderService(p, "CertStore",
"LDAP", "sun.security.provider.certpath.ldap.LDAPCertStore",
null, attrs));
return null;
}
});
/*
* CertStore
* attrs: LDAPSchema, ImplementedIn
*/
putService(new ProviderService(p, "CertStore",
"LDAP", "sun.security.provider.certpath.ldap.LDAPCertStore",
null, attrs));
return null;
};
AccessController.doPrivileged(pa);
}
}