mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
match Java's schizophrenic concept of inner class access modifiers
An inner class has two sets of modifier flags: one is declared in the usual place in the class file and the other is part of the InnerClasses attribute. Not only is that redundant, but they can contradict, and the VM can't just pick one and roll with it. Instead, Class.getModifiers must return the InnerClasses version, whereas reflection must check the top-level version. So even if Class.getModifiers says the class is protected, it might still be public for the purpose of reflection depending on what the InnerClasses attribute says. Crazy? Yes.
This commit is contained in:
@ -30,6 +30,7 @@ import java.lang.annotation.Annotation;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
@ -439,6 +440,19 @@ public final class Class <T> implements Type, AnnotatedElement {
|
||||
}
|
||||
|
||||
public int getModifiers() {
|
||||
ClassAddendum addendum = vmClass.addendum;
|
||||
if (addendum != null) {
|
||||
InnerClassReference[] table = addendum.innerClassTable;
|
||||
if (table != null) {
|
||||
for (int i = 0; i < table.length; ++i) {
|
||||
InnerClassReference reference = table[i];
|
||||
if (Arrays.equals(vmClass.name, reference.inner)) {
|
||||
return reference.flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vmClass.flags;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user