Skip to content

Commit 4e90d74

Browse files
c-clearyAlekseiEfimov
authored andcommitted
8048199: Replace anonymous inner classes with lambdas, where applicable, in JNDI
Reviewed-by: rriggs, dfuchs, aefimov, chegar
1 parent 6293299 commit 4e90d74

File tree

5 files changed

+36
-84
lines changed

5 files changed

+36
-84
lines changed

src/java.naming/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -59,12 +59,8 @@ final class LdapBindingEnumeration
5959
if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) {
6060
// serialized object or object reference
6161
try {
62-
obj = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
63-
@Override
64-
public Object run() throws NamingException {
65-
return Obj.decodeObject(attrs);
66-
}
67-
}, acc);
62+
PrivilegedExceptionAction<Object> pa = () -> Obj.decodeObject(attrs);
63+
obj = AccessController.doPrivileged(pa, acc);
6864
} catch (PrivilegedActionException e) {
6965
throw (NamingException)e.getException();
7066
}

src/java.naming/share/classes/com/sun/jndi/ldap/LdapPoolManager.java

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -395,47 +395,18 @@ private static void d(String msg, String o) {
395395
}
396396
}
397397

398-
private static final String getProperty(final String propName,
399-
final String defVal) {
400-
return AccessController.doPrivileged(
401-
new PrivilegedAction<String>() {
402-
public String run() {
403-
try {
404-
return System.getProperty(propName, defVal);
405-
} catch (SecurityException e) {
406-
return defVal;
407-
}
408-
}
409-
});
398+
private static final String getProperty(final String propName, final String defVal) {
399+
PrivilegedAction<String> pa = () -> System.getProperty(propName, defVal);
400+
return AccessController.doPrivileged(pa);
410401
}
411402

412-
private static final int getInteger(final String propName,
413-
final int defVal) {
414-
Integer val = AccessController.doPrivileged(
415-
new PrivilegedAction<Integer>() {
416-
public Integer run() {
417-
try {
418-
return Integer.getInteger(propName, defVal);
419-
} catch (SecurityException e) {
420-
return defVal;
421-
}
422-
}
423-
});
424-
return val.intValue();
403+
private static final int getInteger(final String propName, final int defVal) {
404+
PrivilegedAction<Integer> pa = () -> Integer.getInteger(propName, defVal);
405+
return AccessController.doPrivileged(pa);
425406
}
426407

427-
private static final long getLong(final String propName,
428-
final long defVal) {
429-
Long val = AccessController.doPrivileged(
430-
new PrivilegedAction<Long>() {
431-
public Long run() {
432-
try {
433-
return Long.getLong(propName, defVal);
434-
} catch (SecurityException e) {
435-
return defVal;
436-
}
437-
}
438-
});
439-
return val.longValue();
408+
private static final long getLong(final String propName, final long defVal) {
409+
PrivilegedAction<Long> pa = () -> Long.getLong(propName, defVal);
410+
return AccessController.doPrivileged(pa);
440411
}
441412
}

src/java.naming/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -119,12 +119,8 @@ protected SearchResult createItem(String dn, Attributes attrs,
119119
// Entry contains Java-object attributes (ser/ref object)
120120
// serialized object or object reference
121121
try {
122-
obj = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
123-
@Override
124-
public Object run() throws NamingException {
125-
return Obj.decodeObject(attrs);
126-
}
127-
}, acc);
122+
PrivilegedExceptionAction<Object> pea = () -> Obj.decodeObject(attrs);
123+
obj = AccessController.doPrivileged(pea, acc);
128124
} catch (PrivilegedActionException e) {
129125
throw (NamingException)e.getException();
130126
}

src/java.naming/share/classes/javax/naming/ldap/StartTlsRequest.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -220,23 +220,13 @@ private ConfigurationException wrapException(Exception e) {
220220
* Acquire the class loader associated with this thread.
221221
*/
222222
private final ClassLoader getContextClassLoader() {
223-
return AccessController.doPrivileged(
224-
new PrivilegedAction<ClassLoader>() {
225-
public ClassLoader run() {
226-
return Thread.currentThread().getContextClassLoader();
227-
}
228-
}
229-
);
223+
PrivilegedAction<ClassLoader> pa = Thread.currentThread()::getContextClassLoader;
224+
return AccessController.doPrivileged(pa);
230225
}
231226

232227
private static final boolean privilegedHasNext(final Iterator<StartTlsResponse> iter) {
233-
Boolean answer = AccessController.doPrivileged(
234-
new PrivilegedAction<Boolean>() {
235-
public Boolean run() {
236-
return Boolean.valueOf(iter.hasNext());
237-
}
238-
});
239-
return answer.booleanValue();
228+
PrivilegedAction<Boolean> pa = iter::hasNext;
229+
return AccessController.doPrivileged(pa);
240230
}
241231

242232
private static final long serialVersionUID = 4441679576360753397L;

src/java.naming/share/classes/sun/security/provider/certpath/ldap/JdkLDAP.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -73,21 +73,20 @@ public JdkLDAP() {
7373
super("JdkLDAP", PROVIDER_VER, "JdkLDAP Provider (implements LDAP CertStore)");
7474

7575
final Provider p = this;
76-
AccessController.doPrivileged(new PrivilegedAction<Void>() {
77-
public Void run() {
78-
HashMap<String, String> attrs = new HashMap<>(2);
79-
attrs.put("LDAPSchema", "RFC2587");
80-
attrs.put("ImplementedIn", "Software");
76+
PrivilegedAction<Void> pa = () -> {
77+
HashMap<String, String> attrs = new HashMap<>(2);
78+
attrs.put("LDAPSchema", "RFC2587");
79+
attrs.put("ImplementedIn", "Software");
8180

82-
/*
83-
* CertStore
84-
* attrs: LDAPSchema, ImplementedIn
85-
*/
86-
putService(new ProviderService(p, "CertStore",
87-
"LDAP", "sun.security.provider.certpath.ldap.LDAPCertStore",
88-
null, attrs));
89-
return null;
90-
}
91-
});
81+
/*
82+
* CertStore
83+
* attrs: LDAPSchema, ImplementedIn
84+
*/
85+
putService(new ProviderService(p, "CertStore",
86+
"LDAP", "sun.security.provider.certpath.ldap.LDAPCertStore",
87+
null, attrs));
88+
return null;
89+
};
90+
AccessController.doPrivileged(pa);
9291
}
9392
}

0 commit comments

Comments
 (0)