Repository: pinpoint-apm/pinpoint
Issue: Thrift plugin depends on commons-lang3
Labels: bug

Thrift plugin seems like developed based on Thrift 0.9.1, which dependes on commons-lang3. The plugin uses classes of commons-lang3 too. But Thrfit 0.9.2 removed commons-lang3 dependency. As a result, when pinpoint is applied to an application which uses Thrift 0.9.2 but not commons-lang3, an exception occurs:

```
java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
        at com.navercorp.pinpoint.plugin.thrift.ThriftUtils.getClientServiceName(ThriftUtils.java:59)
        at com.navercorp.pinpoint.plugin.thrift.interceptor.client.TServiceClientSendBaseInterceptor.before(TServiceClientSendBaseInterceptor.java:124)
        at com.navercorp.pinpoint.profiler.plugin.interceptor.GroupedSimpleAroundInterceptor.before(GroupedSimpleAroundInterceptor.java:48)
        at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java)
```


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/plugins/thrift/pom.xml b/plugins/thrift/pom.xml
index dbd629f00323..630b56c2d087 100644
--- a/plugins/thrift/pom.xml
+++ b/plugins/thrift/pom.xml
@@ -24,11 +24,6 @@
             <artifactId>libthrift</artifactId>
             <scope>provided</scope>
         </dependency>
-        
-        <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-lang3</artifactId>
-        </dependency>
 
         <!-- Logging depedencies -->
         <dependency>
@@ -50,7 +45,6 @@
             <artifactId>log4j</artifactId>
             <scope>compile</scope>
         </dependency>
-        
     </dependencies>
 
 </project>
\ No newline at end of file
diff --git a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftUtils.java b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftUtils.java
index 7d14d13af088..0391047e6a49 100644
--- a/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftUtils.java
+++ b/plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/ThriftUtils.java
@@ -18,8 +18,8 @@
 
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
+import java.util.regex.Pattern;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.thrift.TBaseAsyncProcessor;
 import org.apache.thrift.TBaseProcessor;
 import org.apache.thrift.TServiceClient;
@@ -29,16 +29,25 @@
  * @author HyunGil Jeong
  */
 public class ThriftUtils implements ThriftConstants {
+    
+    private static final Pattern DOT_PATTERN = Pattern.compile("\\.");
 
     private ThriftUtils() {}
     
+    private static String convertDotPathToUriPath(String dotPath) {
+        if (dotPath == null) {
+            return "";
+        }
+        return DOT_PATTERN.matcher(dotPath).replaceAll("/");
+    }
+    
     /**
      * Returns the name of the specified {@link org.apache.thrift.TBaseProcessor TBaseProcessor}
      * as uri to be used in Pinpoint.
      */
     public static String getProcessorNameAsUri(TBaseProcessor<?> processor) {
         String actualProcessorName = processor.getClass().getName();
-        return StringUtils.replace(PROCESSOR_PATTERN.matcher(actualProcessorName).replaceAll("."), ".", "/"); 
+        return convertDotPathToUriPath(PROCESSOR_PATTERN.matcher(actualProcessorName).replaceAll("."));
     }
     
     /**
@@ -47,7 +56,7 @@ public static String getProcessorNameAsUri(TBaseProcessor<?> processor) {
      */
     public static String getAsyncProcessorNameAsUri(TBaseAsyncProcessor<?> asyncProcessor) {
         String actualAsyncProcessorName = asyncProcessor.getClass().getName();
-        return StringUtils.replace(ASYNC_PROCESSOR_PATTERN.matcher(actualAsyncProcessorName).replaceAll("."), ".", "/");
+        return convertDotPathToUriPath(ASYNC_PROCESSOR_PATTERN.matcher(actualAsyncProcessorName).replaceAll("."));
     }
     
     /**
@@ -56,7 +65,7 @@ public static String getAsyncProcessorNameAsUri(TBaseAsyncProcessor<?> asyncProc
      */
     public static String getClientServiceName(TServiceClient client) {
         String clientClassName = client.getClass().getName();
-        return StringUtils.replace(CLIENT_PATTERN.split(clientClassName)[0], ".", "/");
+        return convertDotPathToUriPath(CLIENT_PATTERN.split(clientClassName)[0]);
     }
     
     /**
@@ -65,7 +74,7 @@ public static String getClientServiceName(TServiceClient client) {
      */
     public static String getAsyncMethodCallName(TAsyncMethodCall<?> asyncMethodCall) {
         String asyncMethodCallClassName = asyncMethodCall.getClass().getName();
-        return StringUtils.replace(ASYNC_METHOD_CALL_PATTERN.matcher(asyncMethodCallClassName).replaceAll("."), ".", "/");
+        return convertDotPathToUriPath(ASYNC_METHOD_CALL_PATTERN.matcher(asyncMethodCallClassName).replaceAll("."));
     }
 
     /**


Test patch:
diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT.java
index f81d7d27c7f1..f8c577307007 100644
--- a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT.java
+++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftHalfSyncHalfAsyncServerAsyncIT.java
@@ -40,7 +40,7 @@
  */
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION)
-@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "org.apache.commons:commons-lang3:3.3.2", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
+@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
 public class ThriftHalfSyncHalfAsyncServerAsyncIT extends EchoTestRunner<THsHaServer> {
 
     @Override
diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT.java
index 36c9fb62d2db..670fd1b23c9d 100644
--- a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT.java
+++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftNonblockingServerAsyncIT.java
@@ -40,7 +40,7 @@
  */
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION)
-@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "org.apache.commons:commons-lang3:3.3.2", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
+@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
 public class ThriftNonblockingServerAsyncIT extends EchoTestRunner<TNonblockingServer> {
 
     @Override
diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT.java
index 2f8711004520..ec81e47e930f 100644
--- a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT.java
+++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/asynchronous/ThriftThreadedSelectorServerAsyncIT.java
@@ -40,7 +40,7 @@
  */
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION)
-@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "org.apache.commons:commons-lang3:3.3.2", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
+@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
 public class ThriftThreadedSelectorServerAsyncIT extends EchoTestRunner<TThreadedSelectorServer> {
 
     @Override
diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT.java
index aaabaf9717b8..f426093024f1 100644
--- a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT.java
+++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftHalfSyncHalfAsyncServerIT.java
@@ -40,7 +40,7 @@
  */
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION)
-@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "org.apache.commons:commons-lang3:3.3.2", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
+@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
 public class ThriftHalfSyncHalfAsyncServerIT extends EchoTestRunner<THsHaServer> {
 
     @Override
diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT.java
index 041f4ccd1652..58ae440ea8f3 100644
--- a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT.java
+++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftNonblockingServerIT.java
@@ -40,7 +40,7 @@
  */
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION)
-@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "org.apache.commons:commons-lang3:3.3.2", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
+@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
 public class ThriftNonblockingServerIT extends EchoTestRunner<TNonblockingServer> {
 
     @Override
diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftSimpleServerIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftSimpleServerIT.java
index 99b26c536411..dcd375e32c93 100644
--- a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftSimpleServerIT.java
+++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftSimpleServerIT.java
@@ -40,7 +40,7 @@
  */
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION)
-@Dependency({ "org.apache.thrift:libthrift:[0.9.1,)", "org.apache.commons:commons-lang3:3.3.2", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
+@Dependency({ "org.apache.thrift:libthrift:[0.9.1,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
 public class ThriftSimpleServerIT extends EchoTestRunner<TSimpleServer> {
 
     @Override
diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadPoolServerIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadPoolServerIT.java
index 66829a4caa55..05895c3a1232 100644
--- a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadPoolServerIT.java
+++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadPoolServerIT.java
@@ -40,7 +40,7 @@
  */
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION)
-@Dependency({ "org.apache.thrift:libthrift:[0.9.1,)", "org.apache.commons:commons-lang3:3.3.2", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
+@Dependency({ "org.apache.thrift:libthrift:[0.9.1,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
 public class ThriftThreadPoolServerIT extends EchoTestRunner<TThreadPoolServer> {
 
     @Override
diff --git a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT.java b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT.java
index cb2a34f2142b..8efe3d3ab1e9 100644
--- a/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT.java
+++ b/agent/src/test/java/com/navercorp/pinpoint/plugin/thrift/it/synchronous/ThriftThreadedSelectorServerIT.java
@@ -40,7 +40,7 @@
  */
 @RunWith(PinpointPluginTestSuite.class)
 @PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION)
-@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "org.apache.commons:commons-lang3:3.3.2", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
+@Dependency({ "org.apache.thrift:libthrift:[0.9.2,)", "log4j:log4j:1.2.16", "org.slf4j:slf4j-log4j12:1.5.8" })
 public class ThriftThreadedSelectorServerIT extends EchoTestRunner<TThreadedSelectorServer> {
 
     @Override