diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/reflect/ReflectClassImpl.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/reflect/ReflectClassImpl.java index 1e904bf99..3c0229c9e 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/reflect/ReflectClassImpl.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/reflect/ReflectClassImpl.java @@ -335,14 +335,19 @@ public class ReflectClassImpl implements ReflectClass { @Override public ReflectField[] getFields() { if (fieldsCache == null) { - Set visited = new HashSet<>(); - fieldsCache = context.getClassSource() - .getAncestors(classReader.getName()) - .flatMap(cls -> cls.getFields().stream().filter(fld -> fld.getLevel() == AccessLevel.PUBLIC)) - .filter(fld -> visited.add(fld.getName())) - .map(fld -> context.getClass(ValueType.object(fld.getOwnerName())) - .getDeclaredField(fld.getName())) - .toArray(ReflectField[]::new); + resolve(); + if (classReader == null) { + fieldsCache = new ReflectField[0]; + } else { + Set visited = new HashSet<>(); + fieldsCache = context + .getClassSource() + .getAncestors(classReader.getName()) + .flatMap(cls -> cls.getFields().stream().filter(fld -> fld.getLevel() == AccessLevel.PUBLIC)) + .filter(fld -> visited.add(fld.getName())) + .map(fld -> context.getClass(ValueType.object(fld.getOwnerName())).getDeclaredField(fld.getName())) + .toArray(ReflectField[]::new); + } } return fieldsCache.clone(); }