Patrick0308 commented on a change in pull request #5109: URL: https://github.com/apache/skywalking/pull/5109#discussion_r456210367
########## File path: apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java ########## @@ -40,15 +40,14 @@ public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); - ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); /** * For avoid NPE. In this particular case, Execute sql inside the {@link com.mysql.jdbc.ConnectionImpl} constructor, * before the interceptor sets the connectionInfo. - * + * Fixed https://github.com/apache/skywalking/issues/4965. When invoking prepareCall, cacheObject is null. Because it will determine procedures's parameter types by querying the table of proc in mysql. * @see JDBCDriverInterceptor#afterMethod(EnhancedInstance, Method, Object[], Class[], Object) */ - if (connectInfo != null) { - + if (cacheObject != null && cacheObject.getConnectionInfo() != null) { Review comment: Intercepter set `connectionInfo` after `Driver.connect`. So, in the constructor of `ConnectionImpl`, executing built-in SQL will don't have `connectionInfo`. https://github.com/apache/skywalking/blob/e7e72d937b769f40e50ec644a210bc497f2204f9/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java#L44 Both the condition `cacheObject.getConnectionInfo() != null` and the condition `cacheObject != null` are for not log error message and skip the jdbc's built-in SQL. The NPE not affect recording user's SQL. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org