[ https://issues.apache.org/jira/browse/HIVE-26426?focusedWorklogId=794902&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-794902 ]
ASF GitHub Bot logged work on HIVE-26426: ----------------------------------------- Author: ASF GitHub Bot Created on: 25/Jul/22 13:43 Start Date: 25/Jul/22 13:43 Worklog Time Spent: 10m Work Description: zabetak commented on code in PR #3474: URL: https://github.com/apache/hive/pull/3474#discussion_r928893764 ########## ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java: ########## @@ -947,7 +947,7 @@ Pair<Boolean, String> canCBOHandleAst(ASTNode ast, QB qb, PreCboCtx cboCtx) { // Now check QB in more detail. canHandleQbForCbo returns null if query can // be handled. msg = CalcitePlanner.canHandleQbForCbo(queryProperties, conf, true, needToLogMessage); - if (msg == null) { + if (msg == null || msg.isEmpty()) { return Pair.of(true, msg); } msg = msg.substring(0, msg.length() - 2); Review Comment: Checking if `msg.isEmpty` is a reasonable fix to avoid the IOBE here. The code though seems very brittle and relies on various assumptions that are not specified anywhere. As an alternative fix I would propose to delete this line altogether and do the same a few lines above where the same pattern appears. ```suggestion ``` I don't think we need the extra complexity just to remove a space and semicolon (`; `) from a few messages/explains. I doubt anyone will care. WDYT? ########## ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java: ########## @@ -947,7 +947,7 @@ Pair<Boolean, String> canCBOHandleAst(ASTNode ast, QB qb, PreCboCtx cboCtx) { // Now check QB in more detail. canHandleQbForCbo returns null if query can // be handled. msg = CalcitePlanner.canHandleQbForCbo(queryProperties, conf, true, needToLogMessage); - if (msg == null) { + if (msg == null || msg.isEmpty()) { return Pair.of(true, msg); } msg = msg.substring(0, msg.length() - 2); Review Comment: Moreover, I would argue that allowing `CalcitePlanner.canHandleQbForCbo(queryProperties, conf, true, needToLogMessage)` to return an empty `String` is not good either but we can discuss this separately under another JIRA. Issue Time Tracking ------------------- Worklog Id: (was: 794902) Time Spent: 0.5h (was: 20m) > Avoid StringIndexOutOfBoundsException in canCBOHandleAst() method. > ------------------------------------------------------------------ > > Key: HIVE-26426 > URL: https://issues.apache.org/jira/browse/HIVE-26426 > Project: Hive > Issue Type: Bug > Components: HiveServer2 > Reporter: Abhay > Assignee: Abhay > Priority: Minor > Labels: pull-request-available > Time Spent: 0.5h > Remaining Estimate: 0h > > The call to canHandleQbForCbo() can result in an > StringIndexOutOfBoundsException. The assumption in the code is that the msg > can only be null and we handle that but the msg can also be an empty string > if the *verbose* is set to false. This can happen if INFO Logging is not > enabled. We need to handle that case. > https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java#L913 -- This message was sent by Atlassian Jira (v8.20.10#820010)