Skip to content

Comments

Fix non-standard variable naming in Java test files by using static final#2

Open
Copilot wants to merge 3 commits into2.x_25_10_16_02from
copilot/modify-variable-naming-conventions
Open

Fix non-standard variable naming in Java test files by using static final#2
Copilot wants to merge 3 commits into2.x_25_10_16_02from
copilot/modify-variable-naming-conventions

Conversation

Copy link

Copilot AI commented Oct 16, 2025

Description

This PR fixes non-standard variable naming issues in Java test files where instance variables (non-static final fields) were incorrectly using uppercase or UPPER_SNAKE_CASE naming. The fix makes these variables proper constants by changing them from private final to private static final.

Problem

According to Java naming conventions:

  • Instance variables (non-static fields) should use camelCase (e.g., xid, maxCompressedSize, defaultXid)
  • Constants (static final fields) should use UPPER_SNAKE_CASE (e.g., MAX_SIZE, DEFAULT_TIMEOUT)

Several test files in the codebase were violating this convention by using private final with uppercase naming for what should be constants, which can be confusing and makes the code less maintainable.

Solution

Changed private final to private static final to make these variables proper constants, keeping the UPPER_SNAKE_CASE naming convention. This approach is more semantically correct as these are test constants that should be shared across all instances rather than duplicated per instance.

Changes

Fixed variable naming in 10 test files across multiple modules:

Core Module

  • ContextCoreTest.java: Changed private final to private static final for FIRST_KEY, FIRST_VALUE, SECOND_KEY, SECOND_VALUE, NOT_EXIST_KEY
  • RootContextTest.java: Changed private final to private static final for DEFAULT_XID, DEFAULT_BRANCH_TYPE
  • GlobalBeginResponseTest.java: Changed private final to private static final for XID, EXTRA_DATA, RESULT_CODE

Integration Module

  • GrpcTest.java: Changed private final to private static final for XID

Other Modules

  • ZstdUtilTest.java: Changed private final to private static final for MAX_COMPRESSED_SIZE
  • TableMetaTest.java: Changed private final to private static final for COLUMN_ID, COLUMN_USERCODE
  • RejectedPoliciesTest.java: Changed private final to private static final for DEFAULT_CORE_POOL_SIZE, DEFAULT_KEEP_ALIVE_TIME, MAX_QUEUE_SIZE
  • ApplicationKeeper.java: Changed private final to private static final for LOCK, STOP
  • ApolloMockServer.java: Changed private final to private static final for CONFIG_PREFIX_PATH
  • ClusterWatcherManagerTest.java: Changed private final to private static final for TEST_GROUP, TEST_TIMEOUT, TEST_TERM, TEST_CLIENT_ENDPOINT

Example

Before:

public class GlobalBeginResponseTest {
    private final String XID = "test_xid";
    private final String EXTRA_DATA = "test_extra_data";
    
    @Test
    public void testGetSetXid() {
        globalBeginResponse.setXid(XID);
        Assertions.assertEquals(XID, globalBeginResponse.getXid());
    }
}

After:

public class GlobalBeginResponseTest {
    private static final String XID = "test_xid";
    private static final String EXTRA_DATA = "test_extra_data";
    
    @Test
    public void testGetSetXid() {
        globalBeginResponse.setXid(XID);
        Assertions.assertEquals(XID, globalBeginResponse.getXid());
    }
}

Benefits

  • Semantically correct: These are test constants that should be shared across all instances
  • Better performance: Static constants are shared rather than duplicated per instance
  • Follows Java conventions: Constants use static final with UPPER_SNAKE_CASE naming
  • Minimal changes: Only adds the static keyword, keeping variable names unchanged

This change improves code correctness and adherence to Java coding standards without affecting any functionality.

Original prompt

分析Java代码中不规范的变量命名并修改它。


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: slievrly <8758457+slievrly@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze and correct variable naming conventions in Java code Fix non-standard variable naming in Java test files Oct 16, 2025
Copilot AI requested a review from slievrly October 16, 2025 09:18
@slievrly slievrly marked this pull request as ready for review October 16, 2025 09:26
…ad of renaming to camelCase

Co-authored-by: slievrly <8758457+slievrly@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 16, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repository.apache.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/fescar/fescar org.codehaus.plexus.classworlds.launcher.Launcher test-compile -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix non-standard variable naming in Java test files Fix non-standard variable naming in Java test files by using static final Oct 16, 2025
Copilot AI requested a review from slievrly October 16, 2025 09:35
slievrly

This comment was marked as duplicate.

@slievrly
Copy link
Owner

@copilot 请继续检查变量,方法和接口的命名是否符合Java规范并修复它。可能你需要更高级别的规范约束来检查Java代码。

Copy link
Owner

@slievrly slievrly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 请启动任务分析不合业务语义的变量或方法名。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants