This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch queryTest in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 9b39c01b7a717cb44461c0de75fe68bdfe300b78 Author: JackieTien97 <[email protected]> AuthorDate: Wed Dec 18 17:37:27 2024 +0800 Revert "[IOTDB-6353] replace cglib to byte-buddy (#14426)" This reverts commit f62d058a7967618ea5f6b6b4db05a0f0d968b4c0. --- dependencies.json | 2 +- iotdb-core/node-commons/pom.xml | 4 +- .../commons/client/sync/ByteBuddyEnhancer.java | 75 ---------------------- .../sync/SyncThriftClientWithErrorHandler.java | 30 ++++++++- pom.xml | 8 +-- 5 files changed, 34 insertions(+), 85 deletions(-) diff --git a/dependencies.json b/dependencies.json index dfcaa6a317b..0c8ff00acdd 100644 --- a/dependencies.json +++ b/dependencies.json @@ -1,6 +1,6 @@ { "dependencies": [ - "net.bytebuddy:byte-buddy", + "cglib:cglib", "ch.qos.logback:logback-classic", "ch.qos.logback:logback-core", "ch.qos.reload4j:reload4j", diff --git a/iotdb-core/node-commons/pom.xml b/iotdb-core/node-commons/pom.xml index a9d45250027..2243f340bfc 100644 --- a/iotdb-core/node-commons/pom.xml +++ b/iotdb-core/node-commons/pom.xml @@ -140,8 +140,8 @@ <artifactId>nimbus-jose-jwt</artifactId> </dependency> <dependency> - <groupId>net.bytebuddy</groupId> - <artifactId>byte-buddy</artifactId> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/sync/ByteBuddyEnhancer.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/sync/ByteBuddyEnhancer.java deleted file mode 100644 index db72b444c85..00000000000 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/sync/ByteBuddyEnhancer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.iotdb.commons.client.sync; - -import org.apache.iotdb.commons.client.ThriftClient; - -import net.bytebuddy.ByteBuddy; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; -import net.bytebuddy.implementation.MethodDelegation; -import net.bytebuddy.implementation.bind.annotation.Origin; -import net.bytebuddy.implementation.bind.annotation.RuntimeType; -import net.bytebuddy.implementation.bind.annotation.SuperCall; -import net.bytebuddy.implementation.bind.annotation.This; -import net.bytebuddy.matcher.ElementMatcher; -import net.bytebuddy.matcher.ElementMatchers; -import org.apache.thrift.TException; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.concurrent.Callable; - -public class ByteBuddyEnhancer { - public static <V> V createProxy(Class<V> targetClass, Constructor constructor, Object[] args) - throws NoSuchMethodException, - IllegalAccessException, - InvocationTargetException, - InstantiationException { - ElementMatcher.Junction<MethodDescription> matcher = - ElementMatchers.noneOf(Object.class.getDeclaredMethods()); - - return new ByteBuddy() - .subclass(targetClass) - .method(matcher) - .intercept(MethodDelegation.to(SyncThriftClientWithErrorHandler.class)) - .make() - .load(targetClass.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST) - .getLoaded() - .getDeclaredConstructor(constructor.getParameterTypes()) - .newInstance(args); - } - - public static class SyncThriftClientWithErrorHandler { - @RuntimeType - public static Object intercept( - @This Object targetObject, @SuperCall Callable<?> callable, @Origin Method method) - throws TException { - try { - Object result = callable.call(); - return result; - } catch (Throwable t) { - ThriftClient.resolveException(t, (ThriftClient) targetObject); - throw new TException( - "Error in calling method " + method.getName() + ", because: " + t.getMessage(), t); - } - } - } -} diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/sync/SyncThriftClientWithErrorHandler.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/sync/SyncThriftClientWithErrorHandler.java index 9047fb9f3df..06097c9c821 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/sync/SyncThriftClientWithErrorHandler.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/sync/SyncThriftClientWithErrorHandler.java @@ -21,9 +21,15 @@ package org.apache.iotdb.commons.client.sync; import org.apache.iotdb.commons.client.ThriftClient; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; +import org.apache.thrift.TException; + import java.lang.reflect.Constructor; +import java.lang.reflect.Method; -public class SyncThriftClientWithErrorHandler { +public class SyncThriftClientWithErrorHandler implements MethodInterceptor { /** * Note: The caller needs to ensure that the constructor corresponds to the class, or the cast @@ -31,7 +37,25 @@ public class SyncThriftClientWithErrorHandler { */ @SuppressWarnings("unchecked") public static <V extends ThriftClient> V newErrorHandler( - Class<V> targetClass, Constructor<V> constructor, Object... args) throws Exception { - return ByteBuddyEnhancer.createProxy(targetClass, constructor, args); + Class<V> targetClass, Constructor<V> constructor, Object... args) { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(targetClass); + enhancer.setCallback(new SyncThriftClientWithErrorHandler()); + if (constructor == null) { + return (V) enhancer.create(); + } + return (V) enhancer.create(constructor.getParameterTypes(), args); + } + + @Override + public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) + throws Throwable { + try { + return methodProxy.invokeSuper(o, objects); + } catch (Throwable t) { + ThriftClient.resolveException(t, (ThriftClient) o); + throw new TException( + "Error in calling method " + method.getName() + ", because: " + t.getMessage(), t); + } } } diff --git a/pom.xml b/pom.xml index ce2a1a89d0f..60498a1ee01 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ <boost.include.dir/> <!-- This was the last version to support Java 8 --> <caffeine.version>2.9.3</caffeine.version> - <bytebuddy.version>1.14.19</bytebuddy.version> + <cglib.version>3.3.0</cglib.version> <checker-qual.version>3.38.0</checker-qual.version> <cmake.build.type>Release</cmake.build.type> <commons-cli.version>1.5.0</commons-cli.version> @@ -481,9 +481,9 @@ <version>${nimbus-jose-jwt.version}</version> </dependency> <dependency> - <groupId>net.bytebuddy</groupId> - <artifactId>byte-buddy</artifactId> - <version>${bytebuddy.version}</version> + <groupId>cglib</groupId> + <artifactId>cglib</artifactId> + <version>${cglib.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId>
