kileys commented on code in PR #23210:
URL: https://github.com/apache/beam/pull/23210#discussion_r1067317189
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/coders/RowCoderGenerator.java:
##########
@@ -184,6 +186,30 @@ public static Coder<Row> generate(Schema schema) {
return rowCoder;
}
+ private static ClassLoadingStrategy<ClassLoader>
getClassLoadingStrategy(Class<?> targetClass) {
+ try {
+ ClassLoadingStrategy<ClassLoader> strategy;
+ if (ClassInjector.UsingLookup.isAvailable()) {
+ Class<?> methodHandles =
Class.forName("java.lang.invoke.MethodHandles");
+ Object lookup = methodHandles.getMethod("lookup").invoke(null);
+ Method privateLookupIn =
+ methodHandles.getMethod(
+ "privateLookupIn",
+ Class.class,
+ Class.forName("java.lang.invoke.MethodHandles$Lookup"));
+ Object privateLookup = privateLookupIn.invoke(null, targetClass,
lookup);
+ strategy = ClassLoadingStrategy.UsingLookup.of(privateLookup);
+ } else if (ClassInjector.UsingReflection.isAvailable()) {
+ strategy = ClassLoadingStrategy.Default.INJECTION;
+ } else {
+ throw new IllegalStateException("No code generation strategy
available");
+ }
+ return strategy;
+ } catch (ReflectiveOperationException e) {
+ throw new LinkageError(e.getMessage(), e);
+ }
+ }
+
Review Comment:
Can we do this once in a core.util file?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]