classlib: force class initialization in EnumSet implementation in order to get enum constants array filled

This commit is contained in:
Alexey Andreev 2022-09-13 16:03:37 +02:00
parent 2b671b8088
commit fcb13b24ad

View File

@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.teavm.classlib.java.lang.TClass; import org.teavm.classlib.java.lang.TClass;
import org.teavm.platform.Platform; import org.teavm.platform.Platform;
import org.teavm.platform.PlatformClass;
class TGenericEnumSet<E extends Enum<E>> extends TEnumSet<E> { class TGenericEnumSet<E extends Enum<E>> extends TEnumSet<E> {
Class<E> cls; Class<E> cls;
@ -39,7 +40,9 @@ class TGenericEnumSet<E extends Enum<E>> extends TEnumSet<E> {
} }
static Enum<?>[] getConstants(Class<?> cls) { static Enum<?>[] getConstants(Class<?> cls) {
return Platform.getEnumConstants(((TClass<?>) (Object) cls).getPlatformClass()); PlatformClass platformClass = ((TClass<?>) (Object) cls).getPlatformClass();
Platform.initClass(platformClass);
return Platform.getEnumConstants(platformClass);
} }
@Override @Override