Class#getDeclaredClasses(): exclude inner classes of inner classes

Inner classes can have inner classes, but getDeclaredClasses() is
supposed to list *only* the immediate inner classes.

Example: if class Reflection contains a class Hello that contains
a class World, Reflection.class.getDeclaredClasses() must not
include World in its result.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-12-03 16:30:25 -06:00
parent b246804793
commit 0eb2d55da2
2 changed files with 4 additions and 2 deletions

View File

@ -415,7 +415,7 @@ public final class Class <T> implements Type, AnnotatedElement {
byte[] inner = table[i].inner;
if (inner != null && inner.length > 1) {
String name = new String(inner, 0, inner.length - 1);
if (name.startsWith(prefix)) {
if (name.startsWith(prefix) && name.indexOf('$', prefix.length()) < 0) {
Class innerClass = getClassLoader().loadClass(name);
result[counter++] = innerClass;
}

View File

@ -38,7 +38,9 @@ public class Reflection {
if (! v) throw new RuntimeException();
}
private static class Hello { }
private static class Hello {
private class World { }
}
private static void innerClasses() throws Exception {
Class c = Reflection.class;