question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

class cast exception if no viable alternative could be found

See original GitHub issue

Bug Report

Which version of ShardingSphere did you use?

5.0.0-RC1-SNAPSHOT

Commit 63f880bcab14eba5d4ac83ef22fc5ae346a62821

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

SQL statements with schema and quotation work equally compared to 3.x

Actual behavior

The following sql statement causes a class cast exception

databaseTypeName = "PostgreSQL"
sql = "select count(*) from "abc"."order" where ("abc"."order"."user" = ? and "abc"."order"."status" = ?)"

Schema (abc) and table (order) names have been rewritten using the same character set [a-z]

Reason analyze (If you can)

no viable alternative at input '("abc"."order".'

org.antlr.v4.runtime.NoViableAltException

class org.antlr.v4.runtime.tree.ErrorNodeImpl cannot be cast to class org.antlr.v4.runtime.ParserRuleContext (org.antlr.v4.runtime.tree.ErrorNodeImpl and org.antlr.v4.runtime.ParserRuleContext are in unnamed module of loader 'app')
java.lang.ClassCastException: class org.antlr.v4.runtime.tree.ErrorNodeImpl cannot be cast to class org.antlr.v4.runtime.ParserRuleContext (org.antlr.v4.runtime.tree.ErrorNodeImpl and org.antlr.v4.runtime.ParserRuleContext are in unnamed module of loader 'app')
	at org.jooq_3.12.1.POSTGRES.debug(Unknown Source) ~[?:?]
	at org.apache.shardingsphere.sql.parser.core.extractor.impl.dml.PredicateExtractor.extractRecursiveWithParen(PredicateExtractor.java:116) ~[shardingsphere-sql-parser-engine-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.sql.parser.core.extractor.impl.dml.PredicateExtractor.extractRecursiveWithLogicalOperation(PredicateExtractor.java:71) ~[shardingsphere-sql-parser-engine-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.sql.parser.core.extractor.impl.dml.PredicateExtractor.extract(PredicateExtractor.java:65) ~[shardingsphere-sql-parser-engine-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.sql.parser.core.extractor.impl.dml.WhereExtractor.extract(WhereExtractor.java:48) ~[shardingsphere-sql-parser-engine-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.sql.parser.core.extractor.SQLSegmentsExtractorEngine.extract(SQLSegmentsExtractorEngine.java:47) ~[shardingsphere-sql-parser-engine-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.sql.parser.core.SQLParseKernel.parse(SQLParseKernel.java:59) ~[shardingsphere-sql-parser-engine-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.sql.parser.SQLParseEngine.parse0(SQLParseEngine.java:70) ~[shardingsphere-sql-parser-engine-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.sql.parser.SQLParseEngine.parse(SQLParseEngine.java:52) ~[shardingsphere-sql-parser-engine-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.masterslave.route.engine.MasterSlaveRouter.route(MasterSlaveRouter.java:49) ~[master-slave-core-route-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.MasterSlavePreparedStatement.<init>(MasterSlavePreparedStatement.java:70) ~[sharding-jdbc-core-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.MasterSlavePreparedStatement.<init>(MasterSlavePreparedStatement.java:55) ~[sharding-jdbc-core-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.MasterSlaveConnection.prepareStatement(MasterSlaveConnection.java:76) ~[sharding-jdbc-core-5.0.0-RC1-SNAPSHOT.jar:5.0.0-RC1-SNAPSHOT]
	at org.jooq.impl.ProviderEnabledConnection.prepareStatement(ProviderEnabledConnection.java:109) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.SettingsEnabledConnection.prepareStatement(SettingsEnabledConnection.java:73) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.AbstractResultQuery.prepare(AbstractResultQuery.java:273) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:336) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:501) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:470) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.AbstractResultQuery.fetchLazyNonAutoClosing(AbstractResultQuery.java:484) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:653) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:605) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:611) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.SelectImpl.fetchOne(SelectImpl.java:2847) ~[jooq-3.12.1.jar:?]
	at org.jooq.impl.DefaultDSLContext.fetchCount(DefaultDSLContext.java:4283) ~[jooq-3.12.1.jar:?]

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Should be reproducible with the same sql statement and postgres parser.

Example codes for reproduce this issue (such as a github link).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jingshanglucommented, Jun 19, 2020

@encodeering Now ,only select,delete,update,insert is compatible, others will be fixed in future.

0reactions
sandynzcommented, Oct 14, 2021

Since the original problem was fixed, it will be closed now. Welcome to submit new issue for new problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class cast exception java - Stack Overflow
This happens because Main is a subclass of Beta. So if you have an instance of Beta (the x variable) you cannot cast...
Read more >
kotlin.Result cannot be cast to java.util.List · Issue #485 - GitHub
First I thought it's a Kotlin bug and wanted to file an issue there, however, in production and when removing the mockk calls,...
Read more >
Class loading exceptions - IBM
A class cast exception can occur because, when the application is resolving a remote enterprise bean (EJB) object, the application code does not...
Read more >
How to fix java.lang.classcastexception cannot be cast to in Java
As name suggests ClassCastException in Java comes when we try to type cast an object and object is not of the type we...
Read more >
Handling the ClassCastException Runtime Exception in Java
The ClassCastException in Java happens when the JVM tries to cast an object to a class (or in some instances, an interface) and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found