Skip to content

Commit 0cf3dbc

Browse files
committed
Reimplement org.apache.commons.lang3.ClassUtils.hierarchy(Class,
Interfaces) using an AtomicReference
1 parent 14c5c22 commit 0cf3dbc

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The <action> type attribute can be add,update,fix,remove.
9191
<action type="fix" dev="ggregory" due-to="Sridhar Balijepalli, Piotr P. Karwasz">Fix Javadoc typo and improve clarity in defaultIfBlank method #1376.</action>
9292
<action issue="LANG-1773" type="fix" dev="ggregory" due-to="Éamonn McManus, Gary Gregory">Apache Commons Lang no longer builds on Android #1381.</action>
9393
<action issue="LANG-1772" type="fix" dev="ggregory" due-to="James Winters, Piotr P. Karwasz, Gary Gregory">Restrict size of cache to prevent overflow errors #1379.</action>
94+
<action issue="LANG-1772" type="fix" dev="ggregory" due-to="Gary Gregory">Reimplement org.apache.commons.lang3.ClassUtils.hierarchy(Class, Interfaces) using an AtomicReference.</action>
9495
<!-- ADD -->
9596
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Strings and refactor StringUtils.</action>
9697
<action issue="LANG-1747" type="add" dev="ggregory" due-to="Oliver B. Fischer, Gary Gregory">Add StopWatch.run([Failable]Runnable) and get([Failable]Supplier).</action>

src/main/java/org/apache/commons/lang3/ClassUtils.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
import java.util.Map;
3131
import java.util.Objects;
3232
import java.util.Set;
33+
import java.util.concurrent.atomic.AtomicReference;
3334
import java.util.stream.Collectors;
3435

35-
import org.apache.commons.lang3.mutable.MutableObject;
36-
3736
/**
3837
* Operates on classes without using reflection.
3938
*
@@ -1118,19 +1117,17 @@ public static Iterable<Class<?>> hierarchy(final Class<?> type) {
11181117
*/
11191118
public static Iterable<Class<?>> hierarchy(final Class<?> type, final Interfaces interfacesBehavior) {
11201119
final Iterable<Class<?>> classes = () -> {
1121-
final MutableObject<Class<?>> next = new MutableObject<>(type);
1120+
final AtomicReference<Class<?>> next = new AtomicReference<>(type);
11221121
return new Iterator<Class<?>>() {
11231122

11241123
@Override
11251124
public boolean hasNext() {
1126-
return next.getValue() != null;
1125+
return next.get() != null;
11271126
}
11281127

11291128
@Override
11301129
public Class<?> next() {
1131-
final Class<?> result = next.getValue();
1132-
next.setValue(result.getSuperclass());
1133-
return result;
1130+
return next.getAndUpdate(Class::getSuperclass);
11341131
}
11351132

11361133
@Override

0 commit comments

Comments
 (0)