Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JAXB substitutions for native-image #24768

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.function.BooleanSupplier;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

@TargetClass(className = "com.sun.xml.bind.v2.model.nav.ReflectionNavigator", onlyWith = Target_com_sun_xml_bind_v2_model_nav_ReflectionNavigator.Selector.class)
@TargetClass(className = "com.sun.xml.bind.v2.model.nav.ReflectionNavigator")
final class Target_com_sun_xml_bind_v2_model_nav_ReflectionNavigator {

@Substitute
Expand All @@ -26,21 +25,9 @@ public Field[] getEnumConstants(Class clazz) {
}
}

static final class Selector implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
try {
Class.forName("com.sun.xml.bind.v2.model.nav.ReflectionNavigator");
return true;
} catch (Exception e) {
return false;
}
}
}
}

@TargetClass(className = "com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector", onlyWith = Target_com_sun_xml_bind_v2_runtime_reflect_opt_AccessorInjector.Selector.class)
@TargetClass(className = "com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector")
@Substitute
final class Target_com_sun_xml_bind_v2_runtime_reflect_opt_AccessorInjector {

Expand All @@ -56,23 +43,10 @@ public static Class<?> prepare(
return null;
}

static final class Selector implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
try {
Class<?> c = Class.forName("com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector");
c.getDeclaredMethod("prepare", Class.class, Class.class, String.class, String.class, String[].class);
return true;
} catch (Exception e) {
return false;
}
}
}
}

@TargetClass(className = "com.sun.xml.internal.bind.v2.model.annotation.LocatableAnnotation", onlyWith = Target_com_sun_xml_internal_bind_v2_model_annotation_LocatableAnnotation.Selector.class)
final class Target_com_sun_xml_internal_bind_v2_model_annotation_LocatableAnnotation {
@TargetClass(className = "com.sun.xml.bind.v2.model.annotation.LocatableAnnotation")
final class Target_com_sun_xml_bind_v2_model_annotation_LocatableAnnotation {

@Substitute
public static <A extends Annotation> A create(A annotation, Locatable parentSourcePos) {
Expand All @@ -84,85 +58,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
throw new RuntimeException("Not implemented");
}

@TargetClass(className = "com.sun.xml.internal.bind.v2.model.annotation.Locatable", onlyWith = Target_com_sun_xml_internal_bind_v2_model_annotation_LocatableAnnotation.Selector.class)
@TargetClass(className = "com.sun.xml.bind.v2.model.annotation.Locatable")
static final class Locatable {

}

static final class Selector implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
try {
Class.forName("com.sun.xml.internal.bind.v2.model.annotation.LocatableAnnotation");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}
}

@TargetClass(className = "com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator", onlyWith = Target_com_sun_xml_internal_bind_v2_model_nav_ReflectionNavigator.Selector.class)
final class Target_com_sun_xml_internal_bind_v2_model_nav_ReflectionNavigator {

@Substitute
public Field[] getEnumConstants(Class clazz) {
try {
Object[] values = clazz.getEnumConstants();
Field[] fields = new Field[values.length];
for (int i = 0; i < values.length; i++) {
fields[i] = clazz.getField(((Enum) values[i]).name());
}
return fields;
} catch (NoSuchFieldException e) {
// impossible
throw new NoSuchFieldError(clazz.getName() + ": " + e.getMessage());
}
}

static final class Selector implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
try {
Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator");
return true;
} catch (Exception e) {
return false;
}
}
}
}

@TargetClass(className = "com.sun.xml.internal.bind.v2.runtime.reflect.opt.AccessorInjector", onlyWith = Target_com_sun_xml_internal_bind_v2_runtime_reflect_opt_AccessorInjector.Selector.class)
@Substitute
final class Target_com_sun_xml_internal_bind_v2_runtime_reflect_opt_AccessorInjector {

/**
* Loads the optimized class and returns it.
*
* @return null
* if it fails for some reason.
*/
@Substitute
public static Class<?> prepare(
Class beanClass, String templateClassName, String newClassName, String... replacements) {
return null;
}

static final class Selector implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
try {
Class.forName("com.sun.xml.internal.bind.v2.runtime.reflect.opt.AccessorInjector");
return true;
} catch (Exception e) {
return false;
}
}
}
}

class JAXBSubstitutions {
Expand Down