cushon commented on code in PR #23210:
URL: https://github.com/apache/beam/pull/23210#discussion_r1102218037


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/ByteBuddyUtils.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.util;
+
+import java.lang.reflect.Method;
+import net.bytebuddy.dynamic.loading.ClassInjector;
+import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
+
+/** Utilities for working with Byte Buddy. */
+@SuppressWarnings({
+  "nullness", // TODO(https://github.com/apache/beam/issues/20497)
+})
+public final class ByteBuddyUtils {
+  private ByteBuddyUtils() {} // Non-instantiable
+
+  /** Returns a class loading strategy that is compatible with Java 17+. */
+  public static ClassLoadingStrategy<ClassLoader> 
getClassLoadingStrategy(Class<?> targetClass) {
+    try {
+      ClassLoadingStrategy<ClassLoader> strategy;
+      if (ClassInjector.UsingLookup.isAvailable()) {
+        Class<?> methodHandles = 
Class.forName("java.lang.invoke.MethodHandles");

Review Comment:
   I added an overload that takes a classloader.
   
   Do you want me to update the call sites to explicitly pass in classloaders, 
and if so which ones?
   
   And to double-check: a classloader that loads `java.lang.*` classes itself 
instead of delegating to the system classloader is breaking the contract for 
custom classloaders. Do you definitely want to support that kind of 
non-delegating classloading here?



-- 
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]

Reply via email to