Skip to content

Commit

Permalink
[Dubbo-2.7.10] Fix `setSkyWalkingDynamicField(java.lang.Object) not f…
Browse files Browse the repository at this point in the history
…ound` (apache#7517)

* Fix `setSkyWalkingDynamicField(java.lang.Object) not found`

* Polishing.

* Polishing.

* Polishing.
  • Loading branch information
zifeihan authored and goodjava committed May 6, 2021
1 parent 55ab457 commit d8a5998
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.apache.dubbo.common.bytecode;

import java.util.Arrays;
import java.util.stream.Collectors;
import javassist.ClassPool;
import javassist.CtMethod;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.ReflectUtils;

Expand Down Expand Up @@ -150,7 +154,23 @@ private static Wrapper makeWrapper(Class<?> c) {
pts.put(fn, ft);
}

Method[] methods = c.getMethods();
final ClassPool classPool = new ClassPool(ClassPool.getDefault());
classPool.appendClassPath(new CustomizedLoaderClassPath(cl));

List<String> allMethod = new ArrayList<>();
try {
final CtMethod[] ctMethods = classPool.get(c.getName()).getMethods();
for (CtMethod method : ctMethods) {
allMethod.add(ReflectUtils.getDesc(method));
}
} catch (Exception e) {
throw new RuntimeException(e);
}

Method[] methods = Arrays.stream(c.getMethods())
.filter(method -> allMethod.contains(ReflectUtils.getDesc(method)))
.collect(Collectors.toList())
.toArray(new Method[] {});
// get all public method.
boolean hasMethod = hasMethods(methods);
if (hasMethod) {
Expand All @@ -159,7 +179,7 @@ private static Wrapper makeWrapper(Class<?> c) {
sameNameMethodCount.compute(m.getName(),
(key, oldValue) -> oldValue == null ? 1 : oldValue + 1);
}

c3.append(" try{");
for (Method m : methods) {
//ignore Object's method.
Expand Down

0 comments on commit d8a5998

Please sign in to comment.