JIRA #334 - check for null classreader

This commit is contained in:
Guus C. Bloemsma 2018-04-08 16:37:31 +02:00 committed by Alexey Andreev
parent d9c5b3fd04
commit 744eb39e6d

View File

@ -335,15 +335,20 @@ public class ReflectClassImpl<T> implements ReflectClass<T> {
@Override @Override
public ReflectField[] getFields() { public ReflectField[] getFields() {
if (fieldsCache == null) { if (fieldsCache == null) {
resolve();
if (classReader == null) {
fieldsCache = new ReflectField[0];
} else {
Set<String> visited = new HashSet<>(); Set<String> visited = new HashSet<>();
fieldsCache = context.getClassSource() fieldsCache = context
.getClassSource()
.getAncestors(classReader.getName()) .getAncestors(classReader.getName())
.flatMap(cls -> cls.getFields().stream().filter(fld -> fld.getLevel() == AccessLevel.PUBLIC)) .flatMap(cls -> cls.getFields().stream().filter(fld -> fld.getLevel() == AccessLevel.PUBLIC))
.filter(fld -> visited.add(fld.getName())) .filter(fld -> visited.add(fld.getName()))
.map(fld -> context.getClass(ValueType.object(fld.getOwnerName())) .map(fld -> context.getClass(ValueType.object(fld.getOwnerName())).getDeclaredField(fld.getName()))
.getDeclaredField(fld.getName()))
.toArray(ReflectField[]::new); .toArray(ReflectField[]::new);
} }
}
return fieldsCache.clone(); return fieldsCache.clone();
} }