mirror of
https://github.com/corda/corda.git
synced 2025-01-21 03:55:00 +00:00
Merge pull request #201 from dicej/declaring
fix broken Class.getDeclar{ed|ing}Classes implementations
This commit is contained in:
commit
f52ebdc323
@ -405,34 +405,64 @@ public final class Class <T> implements Type, AnnotatedElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Class[] getDeclaredClasses() {
|
public Class[] getDeclaredClasses() {
|
||||||
if (vmClass.addendum == null || vmClass.addendum.innerClassTable == null) {
|
ClassAddendum addendum = vmClass.addendum;
|
||||||
return new Class[0];
|
if (addendum != null) {
|
||||||
|
InnerClassReference[] table = addendum.innerClassTable;
|
||||||
|
if (table != null) {
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < table.length; ++i) {
|
||||||
|
InnerClassReference reference = table[i];
|
||||||
|
if (reference.outer != null
|
||||||
|
&& Arrays.equals(vmClass.name, reference.outer))
|
||||||
|
{
|
||||||
|
++ count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Class[] result = new Class[count];
|
||||||
|
for (int i = 0; i < table.length; ++i) {
|
||||||
|
InnerClassReference reference = table[i];
|
||||||
|
if (reference.outer != null
|
||||||
|
&& Arrays.equals(vmClass.name, reference.outer))
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
result[--count] = getClassLoader().loadClass
|
||||||
|
(new String(reference.inner, 0, reference.inner.length - 1));
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
InnerClassReference[] table = vmClass.addendum.innerClassTable;
|
return new Class[0];
|
||||||
Class[] result = new Class[table.length];
|
}
|
||||||
int counter = 0;
|
|
||||||
String prefix = getName().replace('.', '/') + "$";
|
public Class getDeclaringClass() {
|
||||||
for (int i = 0; i < table.length; ++i) try {
|
ClassAddendum addendum = vmClass.addendum;
|
||||||
byte[] inner = table[i].inner;
|
if (addendum != null) {
|
||||||
if (inner != null && inner.length > 1) {
|
InnerClassReference[] table = addendum.innerClassTable;
|
||||||
String name = new String(inner, 0, inner.length - 1);
|
if (table != null) {
|
||||||
if (name.startsWith(prefix) && name.indexOf('$', prefix.length()) < 0) {
|
for (int i = 0; i < table.length; ++i) {
|
||||||
Class innerClass = getClassLoader().loadClass(name);
|
InnerClassReference reference = table[i];
|
||||||
result[counter++] = innerClass;
|
if (Arrays.equals(vmClass.name, reference.inner)) {
|
||||||
|
if (reference.outer != null) {
|
||||||
|
try {
|
||||||
|
return getClassLoader().loadClass
|
||||||
|
(new String(reference.outer, 0, reference.outer.length - 1));
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new Error(e);
|
|
||||||
}
|
}
|
||||||
if (counter == result.length) {
|
return null;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (counter == 0) {
|
|
||||||
return new Class[0];
|
|
||||||
}
|
|
||||||
Class[] result2 = new Class[counter];
|
|
||||||
System.arraycopy(result, 0, result2, 0, counter);
|
|
||||||
return result2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassLoader getClassLoader() {
|
public ClassLoader getClassLoader() {
|
||||||
|
@ -731,7 +731,7 @@ getDeclaringClass(Thread* t, object c)
|
|||||||
if (table) {
|
if (table) {
|
||||||
for (unsigned i = 0; i < arrayLength(t, table); ++i) {
|
for (unsigned i = 0; i < arrayLength(t, table); ++i) {
|
||||||
object reference = arrayBody(t, table, i);
|
object reference = arrayBody(t, table, i);
|
||||||
if (strcmp
|
if (innerClassReferenceOuter(t, reference) and strcmp
|
||||||
(&byteArrayBody(t, innerClassReferenceInner(t, reference), 0),
|
(&byteArrayBody(t, innerClassReferenceInner(t, reference), 0),
|
||||||
&byteArrayBody(t, className(t, c), 0)) == 0)
|
&byteArrayBody(t, className(t, c), 0)) == 0)
|
||||||
{
|
{
|
||||||
|
@ -243,6 +243,12 @@ public class Reflection {
|
|||||||
expect((Baz.class.getModifiers() & Modifier.PUBLIC) == 0);
|
expect((Baz.class.getModifiers() & Modifier.PUBLIC) == 0);
|
||||||
|
|
||||||
expect(B.class.getDeclaredMethods().length == 0);
|
expect(B.class.getDeclaredMethods().length == 0);
|
||||||
|
|
||||||
|
new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
expect(getClass().getDeclaringClass() == null);
|
||||||
|
}
|
||||||
|
}.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class Baz {
|
protected static class Baz {
|
||||||
|
Loading…
Reference in New Issue
Block a user