Skip to content

[#noissue] Cleanup#12500

Merged
emeroad merged 1 commit intopinpoint-apm:masterfrom
emeroad:#noissue_cleanup1
May 28, 2025
Merged

[#noissue] Cleanup#12500
emeroad merged 1 commit intopinpoint-apm:masterfrom
emeroad:#noissue_cleanup1

Conversation

@emeroad
Copy link
Copy Markdown
Member

@emeroad emeroad commented May 28, 2025

This pull request introduces several changes across multiple files to improve code readability, reduce redundancy, and replace deprecated or less efficient methods with modern alternatives. The most significant updates include the introduction of reusable empty arrays, the replacement of defaultIfNull with Objects.requireNonNullElse, and minor optimizations to array creation and logging.

Codebase simplification:

  • Reusable empty arrays:

    • Added reusable empty arrays like EMPTY_STRING_ARRAY, RESULT_EMPTY_ARRAY, and FUTURE_EMPTY_ARRAY to avoid creating new empty arrays repeatedly. These are used in methods like toArray() across multiple files, including StringUtils, ASMClassNodeAdapter, ParallelResultScanner, and FutureUtils. [1] [2] [3]
  • Optimized array creation:

    • Replaced new String[0] and similar constructs with reusable constants like EMPTY_STRING_ARRAY and RESULT_EMPTY_ARRAY in methods such as toArray() and getInterfaceNames() to improve performance and readability. [1] [2] [3]

Modernization of code:

  • Use of Objects.requireNonNullElse:

    • Replaced ObjectUtils.defaultIfNull with Objects.requireNonNullElse in MetricDefinition to leverage built-in Java functionality for handling default values.
  • Simplified logging:

    • Removed unused Logger instances and related debug checks in PinpointProfilerPackageFilter to streamline the class and eliminate unnecessary dependencies. [1] [2]

Minor improvements:

  • Optimized collection handling:

    • Replaced explicit type declarations in ArrayList instantiation with the diamond operator (<>) for cleaner code in InetAddressUtils.
  • Removed unused utility class:

    • Deleted ObjectUtils, which is no longer needed due to the adoption of Objects.requireNonNullElse.

@emeroad emeroad added this to the 3.1.0 milestone May 28, 2025
@emeroad emeroad requested a review from Copilot May 28, 2025 06:56
Copy link
Copy Markdown

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 cleans up legacy code by replacing custom utility methods with standard Java alternatives and optimizing array creation across multiple modules. Key changes include:

  • Refactoring null handling in MetricDefinition.java by using Objects.requireNonNullElse instead of ObjectUtils.defaultIfNull.
  • Introducing empty array constants (e.g., FUTURE_EMPTY_ARRAY, EMPTY_STRING_ARRAY) to replace in-line array creation, reducing unnecessary allocations.
  • Removing unused logging and deprecated utilities (e.g., ObjectUtils.java) for cleaner code.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
inspector-module/inspector-web/src/main/java/com/navercorp/pinpoint/inspector/web/definition/MetricDefinition.java Replace custom null-check utility calls with standard Java methods.
commons/src/main/java/com/navercorp/pinpoint/common/util/concurrent/FutureUtils.java Use a static empty array constant to optimize allocations in toArray calls.
commons/src/main/java/com/navercorp/pinpoint/common/util/ObjectUtils.java Remove legacy utility class replaced by standard methods.
commons-server/src/main/java/com/navercorp/pinpoint/common/server/util/InetAddressUtils.java Minor cleanup including improved ArrayList initialization and proper import ordering.
commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/parallel/ParallelResultScanner.java Utilize a constant empty array to reduce temporary array creation in toArray calls.
agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/plugin/PinpointProfilerPackageFilter.java Remove unnecessary logging to simplify the class.
agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/ASMClassNodeAdapter.java Replace repetitive empty array creations with a static constant for better performance.
agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/storage/AsyncQueueingUriStatStorage.java Improve type safety by using a pre-declared empty array in collection-to-array conversion.
agent-module/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/spring/StringUtils.java Introduce a constant empty array and use token.isEmpty for clearer string checks.
Comments suppressed due to low confidence (1)

agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/plugin/PinpointProfilerPackageFilter.java:26

  • [nitpick] Removal of logging may reduce debug visibility; please confirm that this cleanup aligns with the intended logging strategy in production environments.
public class PinpointProfilerPackageFilter implements ClassNameFilter {

Comment on lines +57 to +58
this.preProcess = Objects.requireNonNullElse(preProcess, EmptyPreProcessor.INSTANCE.getName());
this.postProcess = Objects.requireNonNullElse(postProcess, EmptyPostProcessor.INSTANCE.getName());
Copy link

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] Ensure that switching from ObjectUtils.defaultIfNull (which applied a toString conversion for non-null values in preProcess and postProcess) to Objects.requireNonNullElse preserves the intended behavior for these fields.

Suggested change
this.preProcess = Objects.requireNonNullElse(preProcess, EmptyPreProcessor.INSTANCE.getName());
this.postProcess = Objects.requireNonNullElse(postProcess, EmptyPostProcessor.INSTANCE.getName());
this.preProcess = Objects.requireNonNullElse(preProcess != null ? preProcess.toString() : null, EmptyPreProcessor.INSTANCE.getName());
this.postProcess = Objects.requireNonNullElse(postProcess != null ? postProcess.toString() : null, EmptyPostProcessor.INSTANCE.getName());

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented May 28, 2025

Codecov Report

Attention: Patch coverage is 56.25000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 33.57%. Comparing base (793ad90) to head (75ea124).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...int/inspector/web/definition/MetricDefinition.java 0.00% 3 Missing ⚠️
...r/context/storage/AsyncQueueingUriStatStorage.java 33.33% 2 Missing ⚠️
...t/common/hbase/parallel/ParallelResultScanner.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #12500      +/-   ##
============================================
- Coverage     33.58%   33.57%   -0.01%     
+ Complexity    10746    10745       -1     
============================================
  Files          3942     3941       -1     
  Lines         91887    91887              
  Branches       9558     9558              
============================================
- Hits          30859    30855       -4     
- Misses        58387    58389       +2     
- Partials       2641     2643       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@emeroad emeroad merged commit a3024f4 into pinpoint-apm:master May 28, 2025
5 checks passed
@emeroad emeroad deleted the #noissue_cleanup1 branch May 28, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants