This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ba45b706c9 Remove useless null judge in SQLHintUtils#containsSQLHint 
method (#32580)
8ba45b706c9 is described below

commit 8ba45b706c93fef0cc6e510b4fd7cd9087ac2b69
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Sun Aug 18 16:36:04 2024 +0800

    Remove useless null judge in SQLHintUtils#containsSQLHint method (#32580)
    
    * Remove useless null judge in SQLHintUtils#containsSQLHint method
    
    * fix unit test
    
    * fix unit test
    
    * optimize code style
---
 .../postgresql/packet/command/PostgreSQLCommandPacketFactoryTest.java | 1 +
 .../main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java  | 4 ++--
 .../proxy/frontend/mysql/command/MySQLCommandPacketFactoryTest.java   | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git 
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactoryTest.java
 
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactoryTest.java
index 6de25b23f93..167b1e054d5 100644
--- 
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactoryTest.java
+++ 
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactoryTest.java
@@ -41,6 +41,7 @@ class PostgreSQLCommandPacketFactoryTest {
     @Test
     void assertNewInstanceWithQueryComPacket() {
         when(payload.getByteBuf()).thenReturn(mock(ByteBuf.class));
+        when(payload.readStringNul()).thenReturn("");
         
assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.SIMPLE_QUERY,
 payload), instanceOf(PostgreSQLComQueryPacket.class));
     }
     
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java
index bca943cf425..ca6abe5a19b 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintUtils.java
@@ -99,8 +99,8 @@ public final class SQLHintUtils {
     }
     
     private static boolean containsSQLHint(final String sql) {
-        return null != sql && 
(sql.contains(SQLHintTokenType.SQL_START_HINT_TOKEN.getKey())
-                || 
sql.contains(SQLHintTokenType.SQL_START_HINT_TOKEN.getAlias())) && 
sql.contains(SQL_COMMENT_PREFIX) && sql.contains(SQL_COMMENT_SUFFIX);
+        return (sql.contains(SQLHintTokenType.SQL_START_HINT_TOKEN.getKey()) 
|| sql.contains(SQLHintTokenType.SQL_START_HINT_TOKEN.getAlias()))
+                && sql.contains(SQL_COMMENT_PREFIX) && 
sql.contains(SQL_COMMENT_SUFFIX);
     }
     
     private static Map<String, String> getSQLHintKeyValues(final String 
hintKeyValueText) {
diff --git 
a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandPacketFactoryTest.java
 
b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandPacketFactoryTest.java
index bf08b74a00c..025fc677c8b 100644
--- 
a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandPacketFactoryTest.java
+++ 
b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandPacketFactoryTest.java
@@ -85,6 +85,7 @@ class MySQLCommandPacketFactoryTest {
     
     @Test
     void assertNewInstanceWithComStmtPreparePacket() {
+        when(payload.readStringEOF()).thenReturn("");
         
assertThat(MySQLCommandPacketFactory.newInstance(MySQLCommandPacketType.COM_STMT_PREPARE,
 payload, connectionSession), instanceOf(MySQLComStmtPreparePacket.class));
     }
     

Reply via email to