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 6da1738092a Enforce non-nested ternary expressions with Checkstyle 
(#39699)
6da1738092a is described below

commit 6da1738092a15a29e516e0b99ace340b1ce64697
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Sep 2 20:33:18 2026 +0800

    Enforce non-nested ternary expressions with Checkstyle (#39699)
---
 CODE_OF_CONDUCT.md                                               | 1 -
 .../protocol/firebird/codec/FirebirdPacketCodecEngine.java       | 5 ++++-
 docs/community/content/involved/conduct/code.cn.md               | 1 -
 docs/community/content/involved/conduct/code.en.md               | 1 -
 .../database/capability/MCPDatabaseCapabilityProviderTest.java   | 9 ++++++---
 .../oracle/visitor/statement/type/OracleDALStatementVisitor.java | 7 ++++++-
 .../handler/admin/executor/show/MySQLShowTablesExecutor.java     | 7 ++++---
 .../proxy/frontend/postgresql/command/query/extended/Portal.java | 7 ++++++-
 .../command/query/simple/PostgreSQLComQueryExecutor.java         | 7 ++++++-
 src/resources/checkstyle.xml                                     | 7 ++++++-
 .../e2e/operation/pipeline/cases/PipelineContainerComposer.java  | 5 ++++-
 11 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
index cc2b6c9c3c6..08fcb432c1d 100644
--- a/CODE_OF_CONDUCT.md
+++ b/CODE_OF_CONDUCT.md
@@ -66,7 +66,6 @@ The following code of conduct is based on full compliance 
with the [Apache Softw
 - Consider using `LinkedList` first, only use `ArrayList` when you need to get 
element values from the collection by index.
 - Collection types that may cause expansion like `ArrayList`, `HashMap` must 
specify initial collection size to avoid expansion.
 - Prefer using ternary operators instead of if else return and assignment 
statements.
-- Nested use of ternary operators is forbidden.
 - In conditional expressions, prefer positive semantics for easier code logic 
understanding. For example: `if (null == param) {} else {}`.
 - Use `@HighFrequencyInvocation` annotation reasonably to focus on performance 
optimization of key methods.
    - When to use `@HighFrequencyInvocation` annotation:
diff --git 
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/codec/FirebirdPacketCodecEngine.java
 
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/codec/FirebirdPacketCodecEngine.java
index 911422f4a59..5ed2cdee112 100644
--- 
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/codec/FirebirdPacketCodecEngine.java
+++ 
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/codec/FirebirdPacketCodecEngine.java
@@ -175,7 +175,10 @@ public final class FirebirdPacketCodecEngine implements 
DatabasePacketCodecEngin
             if (expectedLength < 0) {
                 return -1;
             }
-            return 0 == expectedLength ? readableBytes : readableBytes >= 
expectedLength ? expectedLength : -1;
+            if (0 == expectedLength) {
+                return readableBytes;
+            }
+            return readableBytes >= expectedLength ? expectedLength : -1;
         } catch (final IndexOutOfBoundsException ex) {
             return -1;
         } finally {
diff --git a/docs/community/content/involved/conduct/code.cn.md 
b/docs/community/content/involved/conduct/code.cn.md
index 588c2afa31b..2ce2dadf67b 100644
--- a/docs/community/content/involved/conduct/code.cn.md
+++ b/docs/community/content/involved/conduct/code.cn.md
@@ -70,7 +70,6 @@ chapter = true
  - 优先考虑使用 `LinkedList`,只有在需要通过下标获取集合中元素值时再使用 `ArrayList`。
  - `ArrayList`,`HashMap` 等可能产生扩容的集合类型必须指定集合初始大小,避免扩容。
  - 优先使用三目运算符代替 if else 的返回和赋值语句。
- - 禁止嵌套使用三目运算符。
  - 条件表达式中,优先使用正向语义,以便于理解代码逻辑。例如:`if (null == param) {} else {}`。
  - 合理使用 `@HighFrequencyInvocation` 注解,用于聚焦关键方法性能的优化。
    - 使用 `@HighFrequencyInvocation` 注解的时机:
diff --git a/docs/community/content/involved/conduct/code.en.md 
b/docs/community/content/involved/conduct/code.en.md
index 5644db87076..f27dfa10b6f 100644
--- a/docs/community/content/involved/conduct/code.en.md
+++ b/docs/community/content/involved/conduct/code.en.md
@@ -70,7 +70,6 @@ The following code of conduct is based on full compliance 
with the [Apache Softw
 - Consider using `LinkedList` first, only use `ArrayList` when you need to get 
element values from the collection by index.
 - Collection types that may cause expansion like `ArrayList`, `HashMap` must 
specify initial collection size to avoid expansion.
 - Prefer using ternary operators instead of if else return and assignment 
statements.
-- Nested use of ternary operators is forbidden.
 - In conditional expressions, prefer positive semantics for easier code logic 
understanding. For example: `if (null == param) {} else {}`.
 - Use `@HighFrequencyInvocation` annotation reasonably to focus on performance 
optimization of key methods.
     - When to use `@HighFrequencyInvocation` annotation:
diff --git 
a/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/database/capability/MCPDatabaseCapabilityProviderTest.java
 
b/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/database/capability/MCPDatabaseCapabilityProviderTest.java
index 5b73622add5..d887d9cdf8a 100644
--- 
a/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/database/capability/MCPDatabaseCapabilityProviderTest.java
+++ 
b/mcp/support/src/test/java/org/apache/shardingsphere/mcp/support/database/capability/MCPDatabaseCapabilityProviderTest.java
@@ -181,9 +181,12 @@ class MCPDatabaseCapabilityProviderTest {
     
     private RuntimeDatabaseProfile createDatabaseProfile(final String 
databaseName, final String databaseType, final CapabilityFixture 
capabilityFixture,
                                                          final 
IdentifierCasePolicySet identifierCasePolicySet) {
-        TransactionCapability transactionCapability = 
capabilityFixture.transactionSupported
-                ? capabilityFixture.savepointSupported ? 
TransactionCapability.LOCAL_WITH_SAVEPOINT : TransactionCapability.LOCAL
-                : TransactionCapability.NONE;
+        TransactionCapability transactionCapability;
+        if (capabilityFixture.transactionSupported) {
+            transactionCapability = capabilityFixture.savepointSupported ? 
TransactionCapability.LOCAL_WITH_SAVEPOINT : TransactionCapability.LOCAL;
+        } else {
+            transactionCapability = TransactionCapability.NONE;
+        }
         return new RuntimeDatabaseProfile(databaseName, databaseType, "", 
transactionCapability, new DatabaseIdentifierContext(identifierCasePolicySet));
     }
     
diff --git 
a/parser/sql/engine/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/engine/oracle/visitor/statement/type/OracleDALStatementVisitor.java
 
b/parser/sql/engine/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/engine/oracle/visitor/statement/type/OracleDALStatementVisitor.java
index a8f3c4985a2..3e7e2d87474 100644
--- 
a/parser/sql/engine/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/engine/oracle/visitor/statement/type/OracleDALStatementVisitor.java
+++ 
b/parser/sql/engine/dialect/oracle/src/main/java/org/apache/shardingsphere/sql/parser/engine/oracle/visitor/statement/type/OracleDALStatementVisitor.java
@@ -107,7 +107,12 @@ public final class OracleDALStatementVisitor extends 
OracleStatementVisitor impl
         VariableSegment variable = null == ctx.systemVariable()
                 ? new VariableSegment(ctx.start.getStartIndex(), 
ctx.start.getStopIndex(), ctx.start.getText())
                 : new 
VariableSegment(ctx.systemVariable().start.getStartIndex(), 
ctx.systemVariable().stop.getStopIndex(), ctx.systemVariable().getText());
-        String value = null != ctx.DBID() ? ctx.numberLiterals().getText() : 
null == ctx.setVariableValue() ? null : ctx.setVariableValue().getText();
+        String value;
+        if (null != ctx.DBID()) {
+            value = ctx.numberLiterals().getText();
+        } else {
+            value = null == ctx.setVariableValue() ? null : 
ctx.setVariableValue().getText();
+        }
         return new VariableAssignSegment(ctx.start.getStartIndex(), 
ctx.stop.getStopIndex(), variable, value);
     }
     
diff --git 
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/show/MySQLShowTablesExecutor.java
 
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/show/MySQLShowTablesExecutor.java
index 983dbfb6e59..8e298c89191 100644
--- 
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/show/MySQLShowTablesExecutor.java
+++ 
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/show/MySQLShowTablesExecutor.java
@@ -110,8 +110,9 @@ public final class MySQLShowTablesExecutor implements 
DatabaseAdminQueryExecutor
     }
     
     private LocalDataQueryResultRow getQueryResultRow(final 
ShardingSphereTable table) {
-        return sqlStatement.isContainsFull()
-                ? new LocalDataQueryResultRow(table.getName(), TableType.VIEW 
== table.getType() ? "VIEW" : "BASE TABLE")
-                : new LocalDataQueryResultRow(table.getName());
+        if (sqlStatement.isContainsFull()) {
+            return new LocalDataQueryResultRow(table.getName(), TableType.VIEW 
== table.getType() ? "VIEW" : "BASE TABLE");
+        }
+        return new LocalDataQueryResultRow(table.getName());
     }
 }
diff --git 
a/proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java
 
b/proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java
index c99b38a2dc4..d0be78f4177 100644
--- 
a/proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java
+++ 
b/proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java
@@ -176,7 +176,12 @@ public final class Portal {
         result.add(new PostgreSQLCommandCompletePacket("SET", 0L));
         for (VariableAssignSegment each : sqlStatement.getVariableAssigns()) {
             String variableName = each.getVariable().getVariable();
-            String variableValue = isClientEncodingVariable(variableName) ? 
UTF8 : null == each.getAssignValue() ? null : 
QuoteCharacter.unwrapText(each.getAssignValue());
+            String variableValue;
+            if (isClientEncodingVariable(variableName)) {
+                variableValue = UTF8;
+            } else {
+                variableValue = null == each.getAssignValue() ? null : 
QuoteCharacter.unwrapText(each.getAssignValue());
+            }
             result.add(new PostgreSQLParameterStatusPacket(variableName, 
variableValue));
         }
         return result;
diff --git 
a/proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java
 
b/proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java
index d6c5c51d026..8b48c903680 100644
--- 
a/proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java
+++ 
b/proxy/frontend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java
@@ -130,7 +130,12 @@ public final class PostgreSQLComQueryExecutor implements 
QueryCommandExecutor {
         result.add(new PostgreSQLCommandCompletePacket("SET", 0L));
         for (VariableAssignSegment each : sqlStatement.getVariableAssigns()) {
             String variableName = each.getVariable().getVariable();
-            String variableValue = isClientEncodingVariable(variableName) ? 
UTF8 : null == each.getAssignValue() ? null : 
QuoteCharacter.unwrapText(each.getAssignValue());
+            String variableValue;
+            if (isClientEncodingVariable(variableName)) {
+                variableValue = UTF8;
+            } else {
+                variableValue = null == each.getAssignValue() ? null : 
QuoteCharacter.unwrapText(each.getAssignValue());
+            }
             result.add(new PostgreSQLParameterStatusPacket(variableName, 
variableValue));
         }
         return result;
diff --git a/src/resources/checkstyle.xml b/src/resources/checkstyle.xml
index 06eea0f5cae..cb6f272670f 100644
--- a/src/resources/checkstyle.xml
+++ b/src/resources/checkstyle.xml
@@ -242,7 +242,12 @@
         <module name="ArrayTypeStyle" />
         <module name="AvoidEscapedUnicodeCharacters" />
         <module name="CommentsIndentation" />
-        <module name="DescendantToken" />
+        <module name="DescendantToken">
+            <property name="tokens" value="QUESTION" />
+            <property name="limitedTokens" value="QUESTION" />
+            <property name="maximumNumber" value="1" />
+            <property name="maximumMessage" value="Nested ternary operators 
are forbidden." />
+        </module>
         <module name="FinalParameters">
             <property name="tokens" value="METHOD_DEF, CTOR_DEF, 
LITERAL_CATCH" />
         </module>
diff --git 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/PipelineContainerComposer.java
 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/PipelineContainerComposer.java
index 8f03e453113..80595e7405d 100644
--- 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/PipelineContainerComposer.java
+++ 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/PipelineContainerComposer.java
@@ -173,7 +173,10 @@ public final class PipelineContainerComposer implements 
AutoCloseable {
     }
     
     private String getOperationType(final PipelineJobType<?> jobType, final 
String status) {
-        return isSupportCommitRollback(jobType) ? 
(JobStatus.FINISHED.name().equals(status) ? "COMMIT" : "ROLLBACK") : "DROP";
+        if (isSupportCommitRollback(jobType)) {
+            return JobStatus.FINISHED.name().equals(status) ? "COMMIT" : 
"ROLLBACK";
+        }
+        return "DROP";
     }
     
     private boolean isSupportCommitRollback(final PipelineJobType<?> jobType) {

Reply via email to