You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2024/11/29 07:29:17 UTC

(skywalking-java) branch main updated: Add empty judgment for constructorInterceptPoint (#732)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
     new cb764a7849 Add empty judgment for constructorInterceptPoint (#732)
cb764a7849 is described below

commit cb764a7849ab9210711feda1a7fc5e5a30c1d1a9
Author: Zixin Zhou <co...@163.com>
AuthorDate: Fri Nov 29 15:29:11 2024 +0800

    Add empty judgment for constructorInterceptPoint (#732)
---
 CHANGES.md                                              |  1 +
 .../interceptor/enhance/ClassEnhancePluginDefine.java   | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 8275c7e0fa..0e7dd67ab7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -12,6 +12,7 @@ Release Notes.
 * Add async-profiler feature for performance analysis 
 * Support db.instance tag,db.collection tag and AggregateOperation span for mongodb plugin(3.x/4.x)
 * Improve CustomizeConfiguration by avoiding repeatedly resolve file config
+* Add empty judgment for constructorInterceptPoint
 
 All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/222?closed=1)
 
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java
index f38ddfc5a8..b595d89e92 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/interceptor/enhance/ClassEnhancePluginDefine.java
@@ -112,17 +112,20 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
          */
         if (existedConstructorInterceptPoint) {
             for (ConstructorInterceptPoint constructorInterceptPoint : constructorInterceptPoints) {
+                String constructorInterceptor = constructorInterceptPoint.getConstructorInterceptor();
+                if (StringUtil.isEmpty(constructorInterceptor)) {
+                    throw new EnhanceException("no InstanceConstructorInterceptor define to enhance class " + enhanceOriginClassName);
+                }
                 if (isBootstrapInstrumentation()) {
                     newClassBuilder = newClassBuilder.constructor(constructorInterceptPoint.getConstructorMatcher())
-                                                     .intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.withDefaultConfiguration()
-                                                                                                                 .to(BootstrapInstrumentBoost
-                                                                                                                     .forInternalDelegateClass(constructorInterceptPoint
-                                                                                                                         .getConstructorInterceptor()))));
+                            .intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.withDefaultConfiguration()
+                                    .to(BootstrapInstrumentBoost
+                                            .forInternalDelegateClass(constructorInterceptor))));
                 } else {
                     newClassBuilder = newClassBuilder.constructor(constructorInterceptPoint.getConstructorMatcher())
-                                                     .intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.withDefaultConfiguration()
-                                                                                                                 .to(new ConstructorInter(getPluginName(), constructorInterceptPoint
-                                                                                                                     .getConstructorInterceptor(), classLoader), delegateNamingResolver.resolve(constructorInterceptPoint))));
+                            .intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.withDefaultConfiguration()
+                                    .to(new ConstructorInter(getPluginName(), constructorInterceptor, classLoader),
+                                            delegateNamingResolver.resolve(constructorInterceptPoint))));
                 }
             }
         }