You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/09/01 01:42:01 UTC

(shardingsphere) branch master updated: Remove StringUtils usages and prohibit StringUtils and CollectionUtils imports (#39672)

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

terrymanu 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 4f20c7ad61a Remove StringUtils usages and prohibit StringUtils and CollectionUtils imports (#39672)
4f20c7ad61a is described below

commit 4f20c7ad61ae2ef98225f59f5cd5ad17b41aa095
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Sep 1 09:41:54 2026 +0800

    Remove StringUtils usages and prohibit StringUtils and CollectionUtils imports (#39672)
    
    * Remove StringUtils usages and prohibit StringUtils and CollectionUtils imports
    
    * Remove StringUtils usages and prohibit StringUtils and CollectionUtils imports
---
 .../algorithm/standard/AESEncryptAlgorithm.java    |  3 +-
 .../standard/AESEncryptAlgorithmTest.java          |  2 +-
 .../function/mysql/impl/MySQLBitCountFunction.java | 15 +++++++--
 .../mysql/impl/MySQLBitCountFunctionTest.java      |  1 +
 src/resources/checkstyle.xml                       |  1 +
 .../e2e/env/container/util/DockerImageVersion.java |  5 +--
 .../env/container/util/DockerImageVersionTest.java | 37 ++++++++++++++++++++++
 .../e2e/env/container/util/SQLScriptUtils.java     |  8 +++--
 .../loader/ExternalTestParameterLoader.java        |  3 +-
 9 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
index f12733df0a4..1aa24d7b674 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.encrypt.algorithm.standard;
 
 import lombok.Getter;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
 import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
@@ -65,7 +64,7 @@ public final class AESEncryptAlgorithm implements EncryptAlgorithm {
     @Override
     public AlgorithmConfiguration toConfiguration() {
         return new AlgorithmConfiguration(getType(),
-                PropertiesBuilder.build(new Property(AES_KEY, props.getProperty(AES_KEY)), new Property(DIGEST_ALGORITHM_NAME, StringUtils.upperCase(props.getProperty(DIGEST_ALGORITHM_NAME)))));
+                PropertiesBuilder.build(new Property(AES_KEY, props.getProperty(AES_KEY)), new Property(DIGEST_ALGORITHM_NAME, props.getProperty(DIGEST_ALGORITHM_NAME).toUpperCase())));
     }
     
     @Override
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
index 40d4b05e4a0..f0212527fc8 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
@@ -37,7 +37,7 @@ class AESEncryptAlgorithmTest {
     
     @BeforeEach
     void setUp() {
-        encryptAlgorithm = TypedSPILoader.getService(EncryptAlgorithm.class, "AES", PropertiesBuilder.build(new Property("aes-key-value", "test"), new Property("digest-algorithm-name", "SHA-1")));
+        encryptAlgorithm = TypedSPILoader.getService(EncryptAlgorithm.class, "AES", PropertiesBuilder.build(new Property("aes-key-value", "test"), new Property("digest-algorithm-name", "sha-1")));
     }
     
     @Test
diff --git a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/function/mysql/impl/MySQLBitCountFunction.java b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/function/mysql/impl/MySQLBitCountFunction.java
index 01f5380ea77..be727e4a079 100644
--- a/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/function/mysql/impl/MySQLBitCountFunction.java
+++ b/kernel/sql-federation/compiler/src/main/java/org/apache/shardingsphere/sqlfederation/compiler/sql/function/mysql/impl/MySQLBitCountFunction.java
@@ -29,7 +29,6 @@ import org.apache.calcite.sql.type.SqlTypeFamily;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.sql.validate.SqlUserDefinedFunction;
 import org.apache.calcite.util.BitString;
-import org.apache.commons.lang3.StringUtils;
 
 import java.math.BigInteger;
 import java.util.Arrays;
@@ -61,7 +60,7 @@ public final class MySQLBitCountFunction extends SqlUserDefinedFunction {
             return bitCount((byte[]) value);
         }
         if (value instanceof String) {
-            return StringUtils.isNumeric((String) value) ? Long.bitCount(Long.parseLong((String) value)) : 0;
+            return isNumeric((String) value) ? Long.bitCount(Long.parseLong((String) value)) : 0;
         }
         if (value instanceof BigInteger) {
             return ((BigInteger) value).bitCount();
@@ -84,4 +83,16 @@ public final class MySQLBitCountFunction extends SqlUserDefinedFunction {
         }
         return result;
     }
+    
+    private static boolean isNumeric(final String value) {
+        if (value.isEmpty()) {
+            return false;
+        }
+        for (int each = 0; each < value.length(); each++) {
+            if (!Character.isDigit(value.charAt(each))) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
diff --git a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/function/mysql/impl/MySQLBitCountFunctionTest.java b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/function/mysql/impl/MySQLBitCountFunctionTest.java
index 670e9c395b8..341d76594e4 100644
--- a/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/function/mysql/impl/MySQLBitCountFunctionTest.java
+++ b/kernel/sql-federation/compiler/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/sql/function/mysql/impl/MySQLBitCountFunctionTest.java
@@ -47,6 +47,7 @@ class MySQLBitCountFunctionTest {
                 Arguments.of(null, null),
                 Arguments.of(new byte[]{(byte) 0b00001111}, 4L),
                 Arguments.of("7", 3),
+                Arguments.of("", 0),
                 Arguments.of("abc", 0),
                 Arguments.of(new BigInteger("15"), 4),
                 Arguments.of(3, 2),
diff --git a/src/resources/checkstyle.xml b/src/resources/checkstyle.xml
index a2cafa0efeb..27cbac36d38 100644
--- a/src/resources/checkstyle.xml
+++ b/src/resources/checkstyle.xml
@@ -178,6 +178,7 @@
         <module name="IllegalImport">
             <property name="regexp" value="true" />
             <property name="illegalPkgs" value="sun,.*[.]shaded" />
+            <property name="illegalClasses" value=".*[.]StringUtils([.].*)?,.*[.]CollectionUtils([.].*)?" />
         </module>
         <module name="RedundantImport" />
         <module name="UnusedImports" />
diff --git a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/DockerImageVersion.java b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/DockerImageVersion.java
index c1cc2439738..3f0af7e4a8f 100644
--- a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/DockerImageVersion.java
+++ b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/DockerImageVersion.java
@@ -17,8 +17,6 @@
 
 package org.apache.shardingsphere.test.e2e.env.container.util;
 
-import org.apache.commons.lang3.StringUtils;
-
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -51,9 +49,8 @@ public final class DockerImageVersion {
      * @return major version
      */
     public int getMajorVersion() {
-        String[] split = StringUtils.substringBefore(version, "-").split("\\.");
         try {
-            return Integer.parseInt(split[0]);
+            return Integer.parseInt(version.split("[.-]", 2)[0]);
         } catch (final NumberFormatException ignored) {
             return 0;
         }
diff --git a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/DockerImageVersionTest.java b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/DockerImageVersionTest.java
new file mode 100644
index 00000000000..23c75fbb1b0
--- /dev/null
+++ b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/DockerImageVersionTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.env.container.util;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+class DockerImageVersionTest {
+    
+    @ParameterizedTest(name = "{0}")
+    @CsvSource({
+            "mysql:8.4.0, 8",
+            "mysql:8.4.0-oracle, 8",
+            "mysql:latest, 0"
+    })
+    void assertGetMajorVersion(final String dockerImageName, final int expectedMajorVersion) {
+        assertThat(new DockerImageVersion(dockerImageName).getMajorVersion(), is(expectedMajorVersion));
+    }
+}
diff --git a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/SQLScriptUtils.java b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/SQLScriptUtils.java
index 20c4209922d..2ceb69f95f3 100644
--- a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/SQLScriptUtils.java
+++ b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/util/SQLScriptUtils.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.test.e2e.env.container.util;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.SneakyThrows;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.Strings;
 import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.sqlbatch.DialectSQLBatchOption;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
@@ -42,6 +41,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collection;
 import java.util.LinkedList;
+import java.util.stream.IntStream;
 
 /**
  * SQL script utility class.
@@ -101,7 +101,7 @@ public final class SQLScriptUtils {
                 if (null == sql) {
                     break;
                 }
-                if (!StringUtils.isBlank(sql)) {
+                if (containsNonWhitespace(sql)) {
                     result.add(sql);
                 }
             }
@@ -114,6 +114,10 @@ public final class SQLScriptUtils {
         return null == resourceAsStream ? new FileReader(scriptFilePath) : new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
     }
     
+    private static boolean containsNonWhitespace(final String value) {
+        return IntStream.range(0, value.length()).anyMatch(each -> !Character.isWhitespace(value.charAt(each)));
+    }
+    
     private static void executeBatch(final Connection connection, final Collection<String> sqls) throws SQLException {
         int count = 0;
         try (Statement statement = connection.createStatement()) {
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/external/loader/ExternalTestParameterLoader.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/external/loader/ExternalTestParameterLoader.java
index a1f3bbdedbe..d5d8b8cefa9 100644
--- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/external/loader/ExternalTestParameterLoader.java
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/external/loader/ExternalTestParameterLoader.java
@@ -21,7 +21,6 @@ import com.google.common.base.Strings;
 import com.google.common.io.Files;
 import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.shardingsphere.test.it.sql.parser.external.ExternalSQLTestParameter;
 import org.apache.shardingsphere.test.it.sql.parser.external.env.ExternalEnvironmentContext;
 import org.apache.shardingsphere.test.it.sql.parser.external.loader.strategy.ExternalTestParameterLoadStrategy;
@@ -82,7 +81,7 @@ public final class ExternalTestParameterLoader {
         Collection<FileSummary> resultFileSummaries = loadStrategy.loadSQLCaseFileSummaries(resultURI);
         Map<String, FileSummary> resultFileSummaryMap =
                 resultFileSummaries.stream().collect(Collectors.toMap(fileSummary -> Files.getNameWithoutExtension(fileSummary.getFileName()), Function.identity()));
-        return sqlCaseFileSummaries.stream().filter(each -> StringUtils.isEmpty(caseRegex) || each.getFileName().matches(caseRegex)).flatMap(each -> {
+        return sqlCaseFileSummaries.stream().filter(each -> Strings.isNullOrEmpty(caseRegex) || each.getFileName().matches(caseRegex)).flatMap(each -> {
             List<String> sqlCaseFileContent = loadContent(URI.create(each.getAccessURI()));
             String fileName = Files.getNameWithoutExtension(each.getFileName());
             Optional<FileSummary> resultFileSummary = Optional.ofNullable(resultFileSummaryMap.get(fileName));