Skip to content

Commit

Permalink
Revert "Replace more uses of ClassLoadingStrategy.Default.INJECTION (
Browse files Browse the repository at this point in the history
…#23210)" (#25566)

This reverts commit 2b62912.
  • Loading branch information
Abacn authored Feb 21, 2023
1 parent 903fbf9 commit b92600a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.beam.sdk.coders;

import static org.apache.beam.sdk.util.ByteBuddyUtils.getClassLoadingStrategy;
import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState;

import java.io.IOException;
Expand All @@ -37,6 +36,7 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.description.type.TypeDescription.ForLoadedType;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.implementation.Implementation;
Expand All @@ -55,7 +55,6 @@
import org.apache.beam.sdk.schemas.Schema.Field;
import org.apache.beam.sdk.schemas.Schema.FieldType;
import org.apache.beam.sdk.schemas.SchemaCoder;
import org.apache.beam.sdk.util.common.ReflectHelpers;
import org.apache.beam.sdk.values.Row;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Maps;
Expand Down Expand Up @@ -173,9 +172,7 @@ public static Coder<Row> generate(Schema schema) {
rowCoder =
builder
.make()
.load(
ReflectHelpers.findClassLoader(schema.getClass().getClassLoader()),
getClassLoadingStrategy(schema.getClass()))
.load(Coder.class.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor(Coder[].class, int[].class)
.newInstance((Object) componentCoders, (Object) encodingPosToRowIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/
package org.apache.beam.sdk.schemas.utils;

import static org.apache.beam.sdk.util.ByteBuddyUtils.getClassLoadingStrategy;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
Expand All @@ -27,6 +25,7 @@
import net.bytebuddy.asm.AsmVisitorWrapper;
import net.bytebuddy.description.type.TypeDescription.ForLoadedType;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.implementation.MethodCall;
import net.bytebuddy.implementation.bytecode.StackManipulation;
import net.bytebuddy.implementation.bytecode.assign.TypeCasting;
Expand Down Expand Up @@ -100,7 +99,7 @@ private static <T> SchemaUserTypeCreator createCreator(Class<T> clazz, Schema sc
.make()
.load(
ReflectHelpers.findClassLoader(clazz.getClassLoader()),
getClassLoadingStrategy(clazz))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.beam.sdk.schemas.utils;

import static org.apache.beam.sdk.util.ByteBuddyUtils.getClassLoadingStrategy;
import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull;

import java.lang.reflect.Constructor;
Expand All @@ -44,6 +43,7 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.description.type.TypeDescription.ForLoadedType;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.Implementation.Context;
Expand Down Expand Up @@ -459,7 +459,7 @@ public InstrumentedType prepare(InstrumentedType instrumentedType) {
.make()
.load(
ReflectHelpers.findClassLoader(((Class) fromType).getClassLoader()),
getClassLoadingStrategy((Class) fromType))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/
package org.apache.beam.sdk.schemas.utils;

import static org.apache.beam.sdk.util.ByteBuddyUtils.getClassLoadingStrategy;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand All @@ -30,6 +28,7 @@
import net.bytebuddy.asm.AsmVisitorWrapper;
import net.bytebuddy.description.method.MethodDescription.ForLoadedMethod;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.implementation.Implementation;
Expand Down Expand Up @@ -163,7 +162,7 @@ public static <T> FieldValueGetter createGetter(
.load(
ReflectHelpers.findClassLoader(
typeInformation.getMethod().getDeclaringClass().getClassLoader()),
getClassLoadingStrategy(typeInformation.getMethod().getDeclaringClass()))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down Expand Up @@ -227,7 +226,7 @@ public static FieldValueSetter createSetter(
.load(
ReflectHelpers.findClassLoader(
typeInformation.getMethod().getDeclaringClass().getClassLoader()),
getClassLoadingStrategy(typeInformation.getMethod().getDeclaringClass()))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down Expand Up @@ -291,7 +290,7 @@ public static <T> SchemaUserTypeCreator createConstructorCreator(
.make()
.load(
ReflectHelpers.findClassLoader(clazz.getClassLoader()),
getClassLoadingStrategy(clazz))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down Expand Up @@ -339,7 +338,7 @@ public static <T> SchemaUserTypeCreator createStaticCreator(
.make()
.load(
ReflectHelpers.findClassLoader(clazz.getClassLoader()),
getClassLoadingStrategy(clazz))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/
package org.apache.beam.sdk.schemas.utils;

import static org.apache.beam.sdk.util.ByteBuddyUtils.getClassLoadingStrategy;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -158,7 +156,7 @@ private static <T> SchemaUserTypeCreator createSetFieldCreator(
.make()
.load(
ReflectHelpers.findClassLoader(clazz.getClassLoader()),
getClassLoadingStrategy(clazz))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down Expand Up @@ -210,7 +208,7 @@ public static <T> SchemaUserTypeCreator createConstructorCreator(
.make()
.load(
ReflectHelpers.findClassLoader(clazz.getClassLoader()),
getClassLoadingStrategy(clazz))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down Expand Up @@ -301,7 +299,7 @@ public static <T> SchemaUserTypeCreator createStaticCreator(
.make()
.load(
ReflectHelpers.findClassLoader(field.getDeclaringClass().getClassLoader()),
getClassLoadingStrategy(field.getDeclaringClass()))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down Expand Up @@ -381,7 +379,7 @@ private static <ObjectT, ValueT> FieldValueSetter<ObjectT, ValueT> createSetter(
.make()
.load(
ReflectHelpers.findClassLoader(field.getDeclaringClass().getClassLoader()),
getClassLoadingStrategy(field.getDeclaringClass()))
ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor()
.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.beam.sdk.schemas.utils;

import static org.apache.beam.sdk.util.ByteBuddyUtils.getClassLoadingStrategy;
import static org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull;

import com.google.auto.value.AutoValue;
Expand All @@ -37,6 +36,7 @@
import net.bytebuddy.description.type.TypeDescription.ForLoadedType;
import net.bytebuddy.description.type.TypeDescription.Generic;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.Implementation.Context;
Expand Down Expand Up @@ -66,7 +66,6 @@
import org.apache.beam.sdk.schemas.Schema.FieldType;
import org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.IfNullElse;
import org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.ShortCircuitReturnNull;
import org.apache.beam.sdk.util.common.ReflectHelpers;
import org.apache.beam.sdk.values.Row;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Lists;
Expand Down Expand Up @@ -178,9 +177,7 @@ static RowSelector createRowSelector(SchemaAndDescriptor schemaAndDescriptor) {
return builder
.visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES))
.make()
.load(
ReflectHelpers.findClassLoader(schemaAndDescriptor.getClass().getClassLoader()),
getClassLoadingStrategy(schemaAndDescriptor.getClass()))
.load(Row.class.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
.getLoaded()
.getDeclaredConstructor(Schema.class)
.newInstance(outputSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.beam.sdk.transforms.reflect;

import static org.apache.beam.sdk.util.ByteBuddyUtils.getClassLoadingStrategy;
import static org.apache.beam.sdk.util.common.ReflectHelpers.findClassLoader;

import java.lang.reflect.Constructor;
Expand All @@ -28,6 +27,7 @@
import net.bytebuddy.description.modifier.Visibility;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
import net.bytebuddy.implementation.Implementation;
Expand Down Expand Up @@ -225,7 +225,9 @@ public Constructor<?> load(final OnTimerMethodSpecifier onTimerMethodSpecifier)
Class<? extends OnTimerInvoker<?, ?>> res =
(Class<? extends OnTimerInvoker<?, ?>>)
unloaded
.load(findClassLoader(fnClass.getClassLoader()), getClassLoadingStrategy(fnClass))
.load(
findClassLoader(fnClass.getClassLoader()),
ClassLoadingStrategy.Default.INJECTION)
.getLoaded();
return res;
}
Expand Down Expand Up @@ -275,7 +277,9 @@ public Constructor<?> load(final OnTimerMethodSpecifier onTimerMethodSpecifier)
Class<? extends OnTimerInvoker<?, ?>> res =
(Class<? extends OnTimerInvoker<?, ?>>)
unloaded
.load(findClassLoader(fnClass.getClassLoader()), getClassLoadingStrategy(fnClass))
.load(
findClassLoader(fnClass.getClassLoader()),
ClassLoadingStrategy.Default.INJECTION)
.getLoaded();
return res;
}
Expand Down

This file was deleted.

0 comments on commit b92600a

Please sign in to comment.