[HUDI-736] Simplify ReflectionUtils#getTopLevelClassesInClasspath - #19784
[HUDI-736] Simplify ReflectionUtils#getTopLevelClassesInClasspath#19784LeonxLJX wants to merge 3 commits into
Conversation
Replace the imperative loop with a stream pipeline over the package resources and fix a latent NPE: if ClassLoader#getResources throws an IOException, the previous code left 'resources' null and then called Objects.requireNonNull on it. The simplified version returns an empty stream on error instead.
utafrali
left a comment
There was a problem hiding this comment.
The refactor is a clear improvement: it removes the NPE footgun caused by the null-initialized resources variable and the resulting Objects.requireNonNull crash on IOException. The stream pipeline is more readable. Two issues remain: toDirectory should also catch IllegalArgumentException from new File(URI) (triggered by jar: scheme URLs in all 14 bundle Main callers), and the new IOException recovery path has no test.
|
Please make sure that you follow the PR-description and title template, else CI will fail. Please refer to: https://hudi.apache.org/contribute/how-to-contribute/#opening-pull-requests Please also mention in the PR body that this closes: #14554 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19784 +/- ##
============================================
- Coverage 78.15% 78.01% -0.14%
- Complexity 33691 34008 +317
============================================
Files 2540 2541 +1
Lines 141413 142930 +1517
Branches 17123 17226 +103
============================================
+ Hits 110516 111509 +993
- Misses 23195 23690 +495
- Partials 7702 7731 +29
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…Exception The classpath resource URL may not always be convertible to a File (e.g. non-hierarchical or jar-internal schemes), so toDirectory now also catches IllegalArgumentException instead of propagating it. Adds a unit test covering getTopLevelClassesInClasspath.
Removed duplicate imports for List and Collectors.
Describe the issue this Pull Request addresses
[HUDI-736] ReflectionUtils#getTopLevelClassesInClasspath is written as a verbose imperative loop and contains a latent bug: if ClassLoader#getResources throws an IOException, resources stays null and the subsequent Objects.requireNonNull(resources) throws an NPE instead of degrading gracefully.
Summary and Changelog
Impact
Minor refactor of a utility method used during classpath scanning. Behavior is unchanged for the normal path.
Risk Level
Low - utility method refactor, no behavioral change to public APIs.
Documentation Update
No documentation changes needed.
Contributor's checklist