Skip to content

Conversation

mercyblitz
Copy link
Contributor

@mercyblitz mercyblitz commented Aug 24, 2025

This pull request introduces several enhancements and new features across the codebase, with a focus on improving JSON string escaping, extending collection utilities, and adding a new stack implementation. It also includes minor refactors and test updates to support these changes.

JSON Handling Improvements:

  • Introduced a robust JSON string escaping mechanism in JSONUtils, including a new escape(String) method that properly escapes control characters, quotation marks, backslashes, and Unicode line/paragraph separators (\u2028, \u2029). This ensures JSON output is safe for JavaScript consumption and prevents syntax errors. The append(StringBuilder, String, String) method now uses this escaping. [1] [2] [3]
  • Removed unused logger imports and related code from JSONUtils for code cleanliness. [1] [2] [3]

Collection Utilities:

  • Added a new overloaded addAll(Collection<T>, Iterable<T>) method to CollectionUtils, enabling bulk addition from any Iterable with proper null and empty checks. Also renamed the varargs parameter from values to newValues for clarity. [1] [2]

New Data Structure:

  • Added a new ArrayStack<E> class, a non-thread-safe stack implementation based on ArrayList, providing standard stack operations (push, pop, peek, empty, and search).

Reflection Utilities and Configuration:

  • Added new static imports and a constant (BANNED_METHODS_PROPERTY_NAME) to MethodUtils for supporting method banning via system properties, improving flexibility in reflective operations. [1] [2] [3] [4]

Annotation Processor Enhancements:

  • Improved the extraction of property descriptions in ConfigurationPropertyJSONElementVisitor by falling back to Javadoc comments when the annotation value is blank. [1] [2] [3]
  • Updated test setup in ConfigurationPropertyAnnotationProcessorTest to include MethodUtils in the compiled classes, ensuring coverage of new utility features. [1] [2]

Introduced static methods iterate and forEach to IterableUtils for applying a Consumer to each element of an Iterable. These methods provide convenient and null-safe iteration, with forEach serving as an alias for iterate.
Added unit tests to cover the iterate and forEach utility methods in IterableUtils, including cases with null elements. This improves test coverage and ensures correct handling of null and non-null iterables.
Introduces a new overload of the addAll method in CollectionUtils to support adding elements from an Iterable to a Collection. Also renames the varargs parameter in the existing addAll method for clarity.
Split and reorganized addAll tests for better clarity and coverage. Added new test cases for addAll with different collection types, null collections, and iterables to improve test completeness.
Introduced ArrayStack, a non-thread-safe stack implementation based on ArrayList. Provides standard stack operations such as push, pop, peek, empty, and search.
Introduces ArrayStackTest to verify push, pop, peek, empty, and search operations, including edge cases such as popping or peeking from an empty stack.
@mercyblitz mercyblitz requested a review from Copilot August 24, 2025 04:04
Copy link
Contributor

@Copilot 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Changed buildSignature to a public static method and added detailed Javadoc, including usage examples. Also replaced direct array length access with ArrayUtils.length for consistency.
Introduced a new test case to verify the buildSignature method with various String class methods and parameter types.
Introduces an internal copy of system properties to improve performance when accessing properties multiple times. Adds methods to copy, retrieve, and reset the cached system properties, and updates getSystemProperty to use the cached copy if available.
Introduced tests for copying and resetting system properties, including setup and teardown methods to ensure isolation. Added assertions for property retrieval from the copied properties and default value handling.
Updated ClassLoaderUtils to attempt resolving primitive classes by name if standard class loading fails. This improves compatibility when loading class names that refer to Java primitives.
Introduces a new test method to verify doLoadClass with class, primitive type, and primitive type name inputs. This enhances test coverage for the doLoadClass utility.
Introduces a mechanism to ban specific methods from being discovered by MethodUtils.findMethod, based on a configurable system property. Adds initBannedMethods and clearBannedMethods for managing the banned methods cache, and updates findMethod to return null for banned methods. This allows dynamic control over method availability for security or policy reasons.
Copy link

codecov bot commented Aug 24, 2025

Codecov Report

❌ Patch coverage is 95.31250% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/src/main/java/io/microsphere/json/JSONUtils.java 90.00% 1 Missing and 3 partials ⚠️
...src/main/java/io/microsphere/util/SystemUtils.java 88.88% 0 Missing and 2 partials ⚠️
Files with missing lines Coverage Δ Complexity Δ
.../util/ConfigurationPropertyJSONElementVisitor.java 98.38% <100.00%> (+1.83%) 22.00 <2.00> (+3.00)
...ain/java/io/microsphere/collection/ArrayStack.java 100.00% <100.00%> (ø) 9.00 <9.00> (?)
...ava/io/microsphere/collection/CollectionUtils.java 100.00% <100.00%> (ø) 47.00 <5.00> (+5.00)
.../main/java/io/microsphere/reflect/MethodUtils.java 94.09% <100.00%> (+0.72%) 90.00 <11.00> (+7.00)
...ain/java/io/microsphere/util/ClassLoaderUtils.java 92.27% <100.00%> (+0.10%) 86.00 <0.00> (ø)
...c/main/java/io/microsphere/util/IterableUtils.java 100.00% <100.00%> (ø) 6.00 <4.00> (+4.00)
...src/main/java/io/microsphere/util/SystemUtils.java 95.52% <88.88%> (+3.06%) 10.00 <7.00> (+6.00)
...e/src/main/java/io/microsphere/json/JSONUtils.java 98.18% <90.00%> (-0.83%) 170.00 <9.00> (+10.00) ⬇️

... and 3 files with indirect coverage changes

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

Removed unused Map imports and refactored the banned methods initialization to use a new addBannedMethod utility method. Introduced the public addBannedMethod method to allow banning methods programmatically and updated initBannedMethods to use it for improved clarity and reusability.
Introduces unit tests for the addBannedMethod function to verify that banned methods are correctly excluded from lookup. Adds helper method assertAddBannedMethod for test clarity.
Removed empty 'targets' arrays from existing property definitions for clarity. Added a new configuration property 'microsphere.reflect.banned-methods' for specifying banned methods in MethodUtils.
Introduced a static escape method to JSONUtils for escaping special characters in strings according to JSON and JavaScript requirements. This includes handling control characters, quotes, backslashes, and Unicode line/paragraph separators, improving JSON string safety and compatibility.
Introduced comprehensive test cases for the JSONUtils.escape method, covering null, empty, normal strings, and various special characters such as newline, carriage return, tab, double quote, backslash, and Unicode line separators. These tests ensure correct escaping behavior for JSON string values.
Description attribute now falls back to the field's doc comment if the annotation value is blank. This improves the completeness of generated configuration property metadata.
Copy link

@mercyblitz mercyblitz merged commit f784b8f into microsphere-projects:dev Aug 25, 2025
6 of 18 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.

1 participant