[CONJ-425] java.lang.ClassCastException: [B cannot be cast to java.lang.String Created: 2017-02-06  Updated: 2017-02-09  Resolved: 2017-02-09

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.5.5, 1.5.7
Fix Version/s: 1.5.8

Type: Bug Priority: Major
Reporter: Julien Stegle Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

JDK 1.8.0.25
Windows Server 2012
MariaDB 10.1.19
JPA 2.1.0


Attachments: Text File classcast_java_exception.txt     Text File classcast_procedure.txt    

 Description   

We have a stored procedure called by Java using JPA:
StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery(EXPORT_PROCEDURE_NAME);
storedProcedure.registerStoredProcedureParameter(OUTPUT_ATTRIBUT_NAME, String.class, ParameterMode.OUT);
storedProcedure.execute();
String jsonResult = (String) storedProcedure.getOutputParameterValue(OUTPUT_ATTRIBUT_NAME);

The last line raises an error:
java.lang.ClassCastException: [B cannot be cast to java.lang.String.
The output of our stored procedure is a string containing JSON formatted data looking like this: [

{param1: info1, param2: info2}

]
Here is the header of the "show create procedure" query:
STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | CREATE DEFINER=`xxxx`@`localhost` PROCEDURE `EXPORT_TRANSFER_ALL`(OUT json_result TEXT)

This error seems similar is similar to the one reported here: https://mariadb.atlassian.net/browse/CONJ-28

It seems that we're receiving a byte array instead of string though we're not using a secured connexion to the database.



 Comments   
Comment by Julien Stegle [ 2017-02-07 ]

Also tested with MariaDB 10.1.21 and MariaDB Connector/J 1.5.7. Same error.

Comment by Diego Dupin [ 2017-02-07 ]

Hi julien,

Could you please send the "full show create procedure" (procedure is truncated), and if you could the complete stacktrace ? (I've try to reproduced using VARCHAR BINARY field in stored procedure and TEXT field in procedure like your issue without problem)

Comment by Julien Stegle [ 2017-02-07 ]

Hello Diego,

I just uploaded both the procedure and the stack trace.
I had to anonymize some table names and java package names. Please read xxx and xxx2 as our internal packages.

Best regards,
Julien Stegle

Comment by Diego Dupin [ 2017-02-07 ]

Thanks, those information have permit to reproduced the issue :

    @Test
    public void testResultsetWithInoutParameter() throws Exception {
        createProcedure("issue425", "(OUT testValue TEXT)\n"
                + "BEGIN\n"
                + " set testValue = CONCAT('ll', ',');\n"
                + "END");
        CallableStatement cstmt = sharedConnection.prepareCall("{call issue425(?)}");
        cstmt.registerOutParameter(1, Types.VARCHAR);
 
        cstmt.execute();
        ResultSetMetaData rs = cstmt.getMetaData();
 
        assertEquals("ll,", cstmt.getString(1)); //works
        assertEquals("ll,", cstmt.getObject(1, String.class)); //works
        assertEquals("ll,", cstmt.getObject(1)); // fail, since server return testValue as BLOB -> driver return byte[] without taking in account parameter Types.VARCHAR
    }

Comment by Diego Dupin [ 2017-02-08 ]

correction in done in 1.5.8-SNAPSHOT, available using :

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>
 
<dependencies>
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
        <version>1.5.8-SNAPSHOT</version>
    </dependency>
</dependencies>

could you confirm it solve this issue ?

Comment by Julien Stegle [ 2017-02-08 ]

Hi,

I took the mariadb-java-client-1.5.8-20170208.102402-2.jar from https://oss.sonatype.org/content/repositories/snapshots/org/mariadb/jdbc/mariadb-java-client/1.5.8-SNAPSHOT/ but i can't seem to start my application anymore.
Flyway suddenly flags MariaDB 10.1 as an unsupported database (everything works fine when using driver 1.5.5).

Here is the stacktrace if it helps:

2017-02-08T16:37:36.472+0100 ERROR [com.xxxx.xxxxx2.tasks.DatabaseMigrationTask] (ServerService Thread Pool – 135) Error migrating database with FlyWay: com.googlecode.flyway.core.api.FlywayException: Unsupported Database: MariaDB 10.1
at com.googlecode.flyway.core.dbsupport.DbSupportFactory.createDbSupport(DbSupportFactory.java:94) [flyway-core-2.3.jar:]
at com.googlecode.flyway.core.Flyway.execute(Flyway.java:1177) [flyway-core-2.3.jar:]
at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:819) [flyway-core-2.3.jar:]
at com.xxxx.xxxx2.tasks.DatabaseMigrationTask.migrateDB(DatabaseMigrationTask.java:78) [XXXXXCommons.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_25]
at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:114) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:103) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:53) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:109)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ee.component.ComponentInstantiatorInterceptor.processInvocation(ComponentInstantiatorInterceptor.java:75)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.weld.ejb.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:93) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ejb3.tx.EjbBMTInterceptor.handleInvocation(EjbBMTInterceptor.java:104) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.ejb3.tx.BMTInterceptor.processInvocation(BMTInterceptor.java:56) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43) [wildfly-weld-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:160)
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:133)
at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:89)
at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:122) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:137) [wildfly-ejb3-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_25]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_25]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)

Comment by Diego Dupin [ 2017-02-08 ]

Sorry Julien, last snapshot did miss a commit.
(MetaData did send 'MariaDB'/'MySQL' according to database, not always 'MySQL', causing some framework some issue)

Last SNAPSHOT is right now.

Comment by Julien Stegle [ 2017-02-09 ]

Hello, everything seems to be working fine now. Thanks for your support !

Generated at Thu Feb 08 03:15:34 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.