Skip to content

Conversation

@mercyblitz
Copy link
Contributor

This pull request introduces several improvements and updates across the codebase, focusing mainly on utility enhancements, test coverage, and project configuration. The most significant changes include a refactor of the StringUtils.split method for better handling of edge cases, the addition of a utility method for converting collections to string arrays, expanded test coverage for string utilities, and updates to project dependencies and build configurations.

String Utilities Enhancements:

  • Refactored StringUtils.split to handle null and empty delimiters more robustly, and improved its logic for splitting strings, including support for splitting by empty strings and handling edge cases. [1] [2]
  • Added StringUtils.toStringArray(Collection<String>) utility method to convert collections of strings to string arrays safely.

Test Coverage Improvements:

  • Expanded StringUtilsTest to cover more cases for split, replace, substringBeforeLast, substringAfterLast, and added tests for the new toStringArray method. [1] [2] [3] [4] [5] [6]

Project Configuration and Documentation:

  • Added a CODE_OF_CONDUCT.md file to establish contributor guidelines and foster a welcoming community.
  • Updated the Maven build workflow to include Java 25 in the test matrix, ensuring compatibility with the latest Java version.
  • Upgraded the Spring Framework dependency to version 6.2.11 in the parent POM for improved security and features.

Minor Code and Test Updates:

  • Improved imports and usage of static constants in annotation processor test files and utility tests for clarity and consistency. [1] [2] [3] [4]
  • Fixed substring extraction logic in URLUtils.findSubProtocolsString to correctly handle subprotocols in URLs.

Removed the 'spring-core' test dependency from microsphere-java-core/pom.xml and added multiple Spring Framework source files under src/test/java for testing purposes. This change allows tests to run without relying on the external spring-core dependency.
Bumped the default Spring version to 6.2.11. Added a Maven profile 'spring5' to use Spring 5.3.31 for JDK versions 1.8 to 16, ensuring compatibility with older Java versions.
Reimplemented StringUtils.split to avoid StringTokenizer, handle null and empty delimiters, and added toStringArray utility. Updated StringUtilsTest to cover new edge cases and ensure compatibility with Spring's delimitedListToStringArray.
Corrects the substring indices when extracting the protocol from a URL string, ensuring the returned value does not include a leading character.
Eliminated redundant sleep call in FileUtilsTest to improve test efficiency and clarity.
@mercyblitz mercyblitz added this to the 0.1.6 milestone Oct 4, 2025
@mercyblitz mercyblitz requested a review from Copilot October 4, 2025 07:25
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

Release update introducing enhanced String utilities, expanded tests, new collection-to-array helper, Spring version/profile adjustments, build matrix update, and added community guidelines.

  • Refactored StringUtils.split to support null and empty delimiters plus character-wise splitting when delimiter is empty.
  • Added toStringArray(Collection) and broadened related unit tests.
  • Introduced Spring 5 fallback profile for older JDKs and added Java 25 to CI matrix.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pom.xml Bumped project revision and parent build version.
microsphere-java-parent/pom.xml Upgraded Spring to 6.2.11 with JDK-conditional Spring 5 profile.
microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java Refactored split logic; added toStringArray and annotations; updated examples.
microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java Corrected substring extraction for subprotocols.
microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java Minor documentation formatting tweak.
microsphere-java-core/src/test/java/io/microsphere/util/StringUtilsTest.java Expanded split/replace/substring tests and added toStringArray coverage.
microsphere-java-core/src/test/java/io/microsphere/io/FileUtilsTest.java Refactored an asynchronous test pattern for delete directory IOException scenario.
microsphere-java-core/src/test/java/io/microsphere/lang/ClassDataRepositoryTest.java Removed immutability assertion on returned Set.
microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/TestAnnotation.java Switched to static imports for retention/target constants.
CODE_OF_CONDUCT.md Added contributor code of conduct.
.github/workflows/maven-build.yml Added Java 25 to CI build matrix.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

assertEquals(TEST_EMPTY_STRING, replace(TEST_EMPTY_STRING, "null", null));
assertEquals(TEST_CSV_STRING, replace(TEST_CSV_STRING, "null", "null"));

assertEquals(TEST_EMPTY_STRING, replace(TEST_EMPTY_STRING, null, null));
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Duplicate assertion on lines 180 and 184 adds noise without increasing coverage; remove one of them.

Suggested change
assertEquals(TEST_EMPTY_STRING, replace(TEST_EMPTY_STRING, null, null));

Copilot uses AI. Check for mistakes.
Comment on lines 116 to 120
ExecutorService executor = newSingleThreadExecutor();
executor.submit(this::testDeleteDirectoryOnIOException0);
shutdown(executor);
while (!executor.isTerminated()) {
}
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Exceptions thrown in the submitted task are never observed (no Future captured), so the test can pass despite failures; capture the Future and call get() (e.g., Future<?> f = executor.submit(...); f.get();), eliminating the silent failure.

Copilot uses AI. Check for mistakes.
Comment on lines 119 to 120
while (!executor.isTerminated()) {
}
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Busy-wait loop wastes CPU cycles; replace with executor.awaitTermination(timeout, unit) or Future.get() to block efficiently.

Suggested change
while (!executor.isTerminated()) {
}
executor.awaitTermination(1000, MILLISECONDS);

Copilot uses AI. Check for mistakes.
Comment on lines 145 to 151
* <h3>Example Usage</h3>
* <pre>{@code
* StringUtils.split(null, ",") = []
* StringUtils.split("", null) = []
* StringUtils.split("", ";") = []
* StringUtils.split("abc", "") = ["a", "b", "c"]
* StringUtils.split("a,b,c", ",") = ["a", "b", "c"]
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Document the behavior for a non-empty String with a null delimiter (returns the whole String as a single element) to clarify the difference from empty and blank inputs.

Copilot uses AI. Check for mistakes.
@mercyblitz mercyblitz requested a review from Copilot October 4, 2025 07:30
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

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 117 to 119
executor.submit(this::testDeleteDirectoryOnIOException0);
shutdown(executor);
while (!executor.isTerminated()) {
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Assertions and exceptions inside testDeleteDirectoryOnIOException0 will not fail the test because the Future returned by submit(...) is ignored; any AssertionError thrown in the worker thread is swallowed. Capture the Future and call future.get() (or use executor.submit(...).get()) so failures propagate, or invoke the helper method directly on the test thread.

Suggested change
executor.submit(this::testDeleteDirectoryOnIOException0);
shutdown(executor);
while (!executor.isTerminated()) {
try {
// Capture the Future and call get() to propagate exceptions
executor.submit(this::testDeleteDirectoryOnIOException0).get();
} finally {
shutdown(executor);
while (!executor.isTerminated()) {
}

Copilot uses AI. Check for mistakes.
Comment on lines +188 to +191
if (startIndex <= length) {
// Add rest of String, but not in case of empty input.
result.add(value.substring(startIndex));
}
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Condition 'if (startIndex <= length)' is always true here (startIndex cannot exceed length) given earlier flow and the empty-input guard at line 162, making the check redundant. Remove the conditional and add the tail element unconditionally to simplify.

Suggested change
if (startIndex <= length) {
// Add rest of String, but not in case of empty input.
result.add(value.substring(startIndex));
}
// Add rest of String, but not in case of empty input.
result.add(value.substring(startIndex));

Copilot uses AI. Check for mistakes.
@Test
void testReplace() {
assertNull(replace(null, null, null));
assertEquals(TEST_EMPTY_STRING, replace(TEST_EMPTY_STRING, null, null));
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Duplicate assertion (line 184 repeats line 180) adds no additional coverage; remove the duplicate to reduce noise.

Copilot uses AI. Check for mistakes.
Comment on lines 145 to 153
* <h3>Example Usage</h3>
* <pre>{@code
* StringUtils.split(null, ",") = []
* StringUtils.split("", null) = []
* StringUtils.split("", ";") = []
* StringUtils.split("abc", "") = ["a", "b", "c"]
* StringUtils.split("a,b,c", ",") = ["a", "b", "c"]
* StringUtils.split("a;b;c", ",") = ["a;b;c"]
* StringUtils.split("a,,b,c", ",") = ["a", "", "b", "c"]
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Javadoc omits the behavior for a non-empty input with a null delimiter (returns the entire String as a single-element array). Add an example (e.g., StringUtils.split("abc", null) = ["abc"]) to fully document the null-delimiter case.

Copilot uses AI. Check for mistakes.
Updated the assertSplit method to correctly handle delimiter length checks and assertions. Now, assertions for single-character and multi-character delimiters are separated, ensuring accurate test validation.
Replaces busy-wait loop with assertTrue using awaitTermination for better test reliability and readability in testDeleteDirectoryOnIOException.
Changed the return type of testDeleteDirectoryOnIOException0 from Void to File and updated the return statement to return the test directory. This improves clarity and allows the caller to access the created directory.
Fix the issues from the code-review
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 4, 2025

@codecov
Copy link

codecov bot commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...src/main/java/io/microsphere/util/StringUtils.java 94.73% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ Complexity Δ
...ore/src/main/java/io/microsphere/net/URLUtils.java 90.05% <100.00%> (+1.70%) 119.00 <0.00> (+2.00)
.../main/java/io/microsphere/util/ClassPathUtils.java 84.61% <ø> (ø) 12.00 <0.00> (ø)
...src/main/java/io/microsphere/util/StringUtils.java 99.26% <94.73%> (-0.74%) 89.00 <8.00> (+5.00) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mercyblitz mercyblitz merged commit ec6cba8 into release Oct 4, 2025
7 checks passed
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