opentracing-contrib / java-jdbc

OpenTracing Instrumentation for JDBC
Apache License 2.0
82 stars 56 forks source link

java.lang.IllegalArgumentException: object is not an instance of declaring class #63

Closed mouseDH closed 4 years ago

mouseDH commented 4 years ago

When i integrated alibaba's druid and java-jdbc, somtimes there is an error was thrown,sometimes is ok. the error message is the follow content: java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211] at io.opentracing.contrib.jdbc.DynamicProxy$1.invoke(DynamicProxy.java:68) ~[opentracing-jdbc-0.2.7-SNAPSHOT.jar:na] at com.sun.proxy.$Proxy39.isReadOnly(Unknown Source) ~[na:na] at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:137) ~[druid-1.1.18.jar:1.1.18] at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:77) ~[druid-1.1.18.jar:1.1.18] at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:933) ~[druid-1.1.18.jar:1.1.18] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1897) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1839) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1767) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1255) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1175) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:595) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1404) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:847) ~[spring-beans-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.12.RELEASE.jar:5.1.12.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.11.RELEASE.jar:2.1.11.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.11.RELEASE.jar:2.1.11.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.11.RELEASE.jar:2.1.11.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.1.11.RELEASE.jar:2.1.11.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) ~[spring-boot-2.1.11.RELEASE.jar:2.1.11.RELEASE] at com.example.druidopentracejdbc.DruidOpentracejdbcApplication.main(DruidOpentracejdbcApplication.java:19) ~[classes/:na] my pom.xml: `

org.springframework.boot spring-boot-starter
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.18</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.opentracing.contrib</groupId>
        <artifactId>opentracing-jdbc</artifactId>
        <version>0.2.7-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.47</version>
    </dependency>
</dependencies>`

My application.properties: spring.datasource.druid.url=jdbc:tracing:mysql://***?useUnicode=true&characterEncoding=utf8&useSSL=true spring.datasource.druid.username=*** spring.datasource.druid.password=*** spring.datasource.druid.driver-class-name=io.opentracing.contrib.jdbc.TracingDriver spring.datasource.druid.initial-size=10 spring.datasource.druid.max-active=50 spring.datasource.druid.min-idle=5 spring.datasource.druid.max-wait=1800000 spring.datasource.druid.pool-prepared-statements=false spring.datasource.druid.max-pool-prepared-statement-per-connection-size=-1 spring.datasource.druid.validation-query=select 1 spring.datasource.druid.validation-query-timeout=60 spring.datasource.druid.test-while-idle=true spring.datasource.druid.time-between-eviction-runs-millis=180000 My Test Code: `package com.example.druidopentracejdbc;

import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.sql.DataSource; import java.io.Serializable; import java.sql.Connection;

@SpringBootApplication public class DruidOpentracejdbcApplication implements CommandLineRunner {

@Autowired
DataSource dataSource;

public static void main(String[] args) {
    SpringApplication.run(DruidOpentracejdbcApplication.class, args);
}

@Override
public void run(String... args) throws Exception {
  Connection connection = dataSource.getConnection();
    System.out.println(connection.isReadOnly());;
  connection.close();
    System.out.println();
}

}' It's happen at: image Simetimes the method declareinglcass is com.mysql.jdbc.MySQLConnection, and it's will cause the errors above.

malafeev commented 4 years ago

cc @safris could be related to #60

safris commented 4 years ago

@mouseDH and @malafeev, this is fixed in the current development SNAPSHOT (v0.2.6-SNAPSHOT). It was fixed in this commit in this file. A test for this situation was added here.

I believe it would be best to push v0.2.7, before more people stumble on this issue in 0.2.6.

malafeev commented 4 years ago

I was confused by

<dependency>
  <groupId>io.opentracing.contrib</groupId>
  <artifactId>opentracing-jdbc</artifactId>
  <version>0.2.7-SNAPSHOT</version
</dependency>
safris commented 4 years ago

Sorry, please ignore that. Once you release v0.2.7, I'll update this in SpecialAgent.

malafeev commented 4 years ago

@mouseDH 0.2.7 version is released, please try

mouseDH commented 4 years ago

@malafeev @safris Thks for reply. I will try it!

malafeev commented 4 years ago

@mouseDH can be this issue closed now?

malafeev commented 4 years ago

please reopen if issue still exists

mouseDH commented 4 years ago

yeah, this issue can be closed! thks