状态:原创
my origin isuue:Sharding-JDBC 4.1.1:Error caused by column name is ‘’ of SQL query statement · Issue #10954 · apache/shardingsphere · GitHub
Expected behavior
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at org.apache.shardingsphere.sql.parser.sql.util.SQLUtil.getParenthesesOffset(SQLUtil.java:98)
at org.apache.shardingsphere.sql.parser.sql.util.SQLUtil.getExpressionWithoutOutsideParentheses(SQLUtil.java:92)
at org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ExpressionProjectionSegment.(ExpressionProjectionSegment.java:47)
at org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.createProjection(MySQLDMLVisitor.java:474)
at org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitProjection(MySQLDMLVisitor.java:434)
at org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitProjection(MySQLDMLVisitor.java:127)
at org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser$ProjectionContext.accept(MySQLStatementParser.java:5370)
at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
This error in shardingsphere-sql-parser-statement-4.1.1.jar.
This class in org.apache.shardingsphere.sql.parser.sql.util.SQLUtil, the method is getParenthesesOffset.
This special case needs to be addressed.
This issue has been addressed in 5.0.0-beta.
So maybe you can consider 5.0.0-beta version for your product env, because version 4. X is no longer maintained.In 4.1.1 version,you can modify the source code of the method in version 4.1.1 and directly introduce the project to replace the method in the jar package.
Complete code there for judge null value
private static int getParenthesesOffset(final String value) {
int result = 0;
if (Strings.isNullOrEmpty(value)) {
return result;
}
while (Paren.PARENTHESES.getLeftParen() == value.charAt(result)) {
result++;
}
return result;
}