The HotSpot native implementation of
Class.getDeclaringClass() cross-checks the relationship between
the nested class and the enclosing class using the "inner_classes"
attributes in respective class files of the two classes. The
current implementation can resolve inner_classes entries which
are class constants other than the two relevant classes. This wastes
time and memory and can also trigger incorrect ClassCircularityErrors
in some cases when getDeclaringClass() is called directly or indirectly
in a class loader's loadClass() implementation.
The HotSpot implementation of the getDeclaringClass()
native method in jvm.cpp actually attempts to avoid
resolving irrelevant constant pool entries by calling
klass_name_at_matches() before calling klass_at().
However, it then calls Reflection:check_for_inner_classes()
which does not attempt to avoid constant pool class
entries with irrelevant class names.