bson/src/main/org/bson/util/ClassAncestry.java
public static <T> List<Class<?>> getAncestry(final Class<T> c) {
        ConcurrentMap<Class<?>, List<Class<?>>> cache = getClassAncestryCache();
        while (true) {
            List<Class<?>> cachedResult = cache.get(c);
            if (cachedResult != null) {
                return cachedResult;
            }
            cache.putIfAbsent(c, computeAncestry(c));
        }
    }
public static <T> List<Class<?>> getAncestry(final Class<T> c) {
        ConcurrentMap<Class<?>, List<Class<?>>> cache = getClassAncestryCache();
        while (true) {
            List<Class<?>> cachedResult = cache.get(c);
            if (cachedResult != null) {
                return cachedResult;
            }
            cache.putIfAbsent(c, computeAncestry(c));
        }
    }
<p>Walks superclass and interface graph, superclasses first, then interfaces, to compute an ancestry list. Supertypes are visited
left
to right. Duplicates are removed such that no Class will appear in the list before one of its subtypes.</p>

<p>Does not need to be synchronized, races are harmless as the Class graph does not change at runtime.</p>