Skip to content

optimize: optimize common module#7721

Merged
YoWuwuuuw merged 10 commits intoapache:2.xfrom
slievrly:2.x_25_10_19_03
Nov 12, 2025
Merged

optimize: optimize common module#7721
YoWuwuuuw merged 10 commits intoapache:2.xfrom
slievrly:2.x_25_10_19_03

Conversation

@slievrly
Copy link
Member

Ⅰ. Describe what this PR did

optimize common module

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Copy link
Contributor

@YoWuwuuuw YoWuwuuuw left a comment

Choose a reason for hiding this comment

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

PR Changes requires registration.

}

@Test
@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this test is limited to Java 8 and Java 11, and CI builds fail.

Error:  Tests run: 28, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.056 s <<< FAILURE! - in org.apache.seata.common.util.ReflectionUtilTest
Error:  org.apache.seata.common.util.ReflectionUtilTest.testModifyStaticFinalFieldEnhanced  Time elapsed: 0.012 s  <<< FAILURE!

Copy link
Member Author

Choose a reason for hiding this comment

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

The higher version of jdk does not allow the reflection of static final fields. This test case has been temporarily removed for now.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the common module by significantly improving test coverage and adding documentation to utility classes. The main focus is on adding comprehensive test cases for existing functionality and improving code maintainability through better comments and documentation.

Key Changes

  • Added extensive test coverage for utility classes (UUIDGenerator, StringUtils, SizeUtil, ReflectionUtil, NumberUtils, NetUtil, etc.)
  • Replaced deprecated Class.newInstance() with getDeclaredConstructor().newInstance() in BeanUtils and EnhancedServiceLoader
  • Added JavaDoc documentation to utility classes (ConfigTools, CycleDependencyHandler, IOUtil, LambdaUtils, etc.)
  • Enhanced error handling by changing silent exception swallowing to logging in IOUtil

Reviewed Changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
common/src/test/java/.../UUIDGeneratorTest.java Added tests for UUID generation validation, multiple UUID uniqueness, and init parameter validation
common/src/test/java/.../StringUtilsTest.java Added duplicate test methods for hasLength and hasText (already covered by existing tests)
common/src/test/java/.../SizeUtilTest.java Added comprehensive tests for size parsing with valid/invalid inputs and boundary conditions
common/src/test/java/.../ReflectionUtilTest.java Added enhanced tests for reflection operations including field/method access and error cases
common/src/test/java/.../CollectionUtilsTest.java Added extensive tests for collection utilities with potential test correctness issues
common/src/main/java/.../BeanUtils.java Replaced deprecated newInstance() with getDeclaredConstructor().newInstance()
common/src/main/java/.../IOUtil.java Changed exception handling from silent ignore to warning logs
common/src/main/java/.../ConfigTools.java Added comprehensive JavaDoc documentation for all public methods
common/src/main/java/.../CycleDependencyHandler.java Added JavaDoc and improved null safety in containsObject method
common/src/main/java/.../EnhancedServiceLoader.java Replaced deprecated newInstance() and added cached CLASS_LOADER field

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +537 to +539
.containsEntry("", "value2")
.containsEntry("key3", "value3")
.hasSize(2);
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

The test assertion on line 539 is incorrect. Looking at the decode logic, when parsing "key1=&=value2", the entry "key1=" will split into ["key1", ""], and the entry "=value2" will split into ["", "value2"]. However, the test expects only 2 entries with keys "" and "key3", which would mean "key1" is missing. The actual result should have 3 entries: ("key1", ""), ("", "value2"), and ("key3", "value3").

Suggested change
.containsEntry("", "value2")
.containsEntry("key3", "value3")
.hasSize(2);
.containsEntry("key1", "")
.containsEntry("", "value2")
.containsEntry("key3", "value3")
.hasSize(3);

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

key is null or empty, will ignore.

slievrly and others added 2 commits November 11, 2025 19:22
…ilsTest.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@slievrly slievrly added this to the 2.6.0 milestone Nov 11, 2025
@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

❌ Patch coverage is 63.63636% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.23%. Comparing base (ca68871) to head (e2ddec1).
⚠️ Report is 1 commits behind head on 2.x.

Files with missing lines Patch % Lines
...ata/common/metadata/namingserver/MetaResponse.java 0.00% 8 Missing ⚠️
...ache/seata/common/util/CycleDependencyHandler.java 0.00% 1 Missing and 2 partials ⚠️
...in/java/org/apache/seata/common/io/FileLoader.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #7721      +/-   ##
============================================
+ Coverage     69.03%   69.23%   +0.19%     
  Complexity      994      994              
============================================
  Files          1322     1322              
  Lines         50167    50173       +6     
  Branches       5932     5931       -1     
============================================
+ Hits          34635    34735     +100     
+ Misses        12590    12526      -64     
+ Partials       2942     2912      -30     
Files with missing lines Coverage Δ
...a/org/apache/seata/common/holder/ObjectHolder.java 100.00% <ø> (ø)
...che/seata/common/loader/EnhancedServiceLoader.java 81.60% <100.00%> (+0.14%) ⬆️
...pache/seata/common/loader/ExtensionDefinition.java 100.00% <100.00%> (+48.38%) ⬆️
...n/java/org/apache/seata/common/util/BeanUtils.java 90.66% <100.00%> (-2.39%) ⬇️
...java/org/apache/seata/common/util/ConfigTools.java 100.00% <ø> (ø)
...main/java/org/apache/seata/common/util/IOUtil.java 75.00% <100.00%> (+5.00%) ⬆️
...java/org/apache/seata/common/util/LambdaUtils.java 66.66% <ø> (+33.33%) ⬆️
...java/org/apache/seata/common/util/StringUtils.java 92.94% <ø> (+0.64%) ⬆️
...in/java/org/apache/seata/common/io/FileLoader.java 68.42% <66.66%> (ø)
...ache/seata/common/util/CycleDependencyHandler.java 87.09% <0.00%> (+4.33%) ⬆️
... and 1 more

... and 20 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@WangzJi
Copy link
Contributor

WangzJi commented Nov 11, 2025

LGTM

Copy link
Contributor

@maple525866 maple525866 left a comment

Choose a reason for hiding this comment

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

LGTM

@YoWuwuuuw YoWuwuuuw merged commit 1f69f34 into apache:2.x Nov 12, 2025
14 of 16 checks passed
YvCeung pushed a commit to YvCeung/incubator-seata that referenced this pull request Dec 25, 2025
* optimize: optimize common module

* format

* fix review

* fix review

* Update common/src/test/java/org/apache/seata/common/util/CollectionUtilsTest.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Jiangke Wu <xingfudeshi@gmail.com>
Co-authored-by: YoWuwuuuw <2216348784@qq.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

5 participants