cushon commented on code in PR #23210:
URL: https://github.com/apache/beam/pull/23210#discussion_r1090974426
##########
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:
That sounds good. I'm happy to consolidate it wherever you prefer, can you
recommend a location? I wasn't sure what the best place for that shared utility
would be.
--
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]