Search in sources :

Example 1 with LazyFinalReference

use of com.oracle.svm.core.util.LazyFinalReference in project graal by oracle.

the class Target_java_lang_reflect_RecordComponent method initEnumConstantsAtRuntime.

@Platforms(Platform.HOSTED_ONLY.class)
public void initEnumConstantsAtRuntime(Class<?> enumClass) {
    /* Adapted from `Class.getEnumConstantsShared`. */
    try {
        Method values = ReflectionUtil.lookupMethod(enumClass, "values");
        enumConstantsReference = new LazyFinalReference<>(() -> initEnumConstantsAtRuntime(values));
    } catch (ReflectionUtilError e) {
        /*
             * This can happen when users concoct enum-like classes that don't comply with the enum
             * spec.
             */
        enumConstantsReference = null;
    } catch (NoClassDefFoundError e) {
        /*
             * This can happen when an enum references a missing class. So, in order to match the
             * JVM behaviour, we rethrow the error at runtime.
             */
        String message = e.getMessage();
        enumConstantsReference = new LazyFinalReference<>(() -> throwNoClassDefFoundErrorAtRuntime(message));
    }
}
Also used : LazyFinalReference(com.oracle.svm.core.util.LazyFinalReference) Method(java.lang.reflect.Method) ReflectionUtilError(com.oracle.svm.util.ReflectionUtil.ReflectionUtilError) Platforms(org.graalvm.nativeimage.Platforms)

Aggregations

LazyFinalReference (com.oracle.svm.core.util.LazyFinalReference)1 ReflectionUtilError (com.oracle.svm.util.ReflectionUtil.ReflectionUtilError)1 Method (java.lang.reflect.Method)1 Platforms (org.graalvm.nativeimage.Platforms)1