Copilot commented on code in PR #7664:
URL: https://github.com/apache/incubator-seata/pull/7664#discussion_r2380708051
##########
sqlparser/seata-sqlparser-druid/src/main/java/org/apache/seata/sqlparser/druid/oscar/OscarOperateRecognizerHolder.java:
##########
@@ -47,7 +48,10 @@ public SQLRecognizer getUpdateRecognizer(String sql,
SQLStatement ast) {
@Override
public SQLRecognizer getSelectForUpdateRecognizer(String sql, SQLStatement
ast) {
- if (((SQLSelectStatement)
ast).getSelect().getFirstQueryBlock().isForUpdate()) {
+ if (((OscarSelectQueryBlock) ((SQLSelectStatement)
ast).getSelect().getFirstQueryBlock())
+ .getForClause()
+ .getOption()
+ == OscarSelectQueryBlock.ForClause.Option.UPDATE) {
Review Comment:
This code performs multiple method calls without null checks. If
`getFirstQueryBlock()`, `getForClause()`, or `getOption()` returns null, this
will throw a NullPointerException. Consider adding null safety checks.
```suggestion
if (!(ast instanceof SQLSelectStatement)) {
return null;
}
SQLSelectStatement selectStatement = (SQLSelectStatement) ast;
if (selectStatement.getSelect() == null) {
return null;
}
if (selectStatement.getSelect().getFirstQueryBlock() == null) {
return null;
}
OscarSelectQueryBlock queryBlock = (OscarSelectQueryBlock)
selectStatement.getSelect().getFirstQueryBlock();
if (queryBlock.getForClause() == null) {
return null;
}
if (queryBlock.getForClause().getOption() == null) {
return null;
}
if (queryBlock.getForClause().getOption() ==
OscarSelectQueryBlock.ForClause.Option.UPDATE) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]