HDDS-16351. FeatureProvider.Feature.of throws NoSuchElementException instead of IllegalArgumentException - #11170
Open
henry3260 wants to merge 2 commits into
Open
HDDS-16351. FeatureProvider.Feature.of throws NoSuchElementException instead of IllegalArgumentException#11170henry3260 wants to merge 2 commits into
henry3260 wants to merge 2 commits into
Conversation
…instead of IllegalArgumentException Feature.of used Optional.get() followed by a null check on the result. Optional.get() never returns null, so the null check was dead code and an unrecognized feature name produced a bare NoSuchElementException instead of the intended IllegalArgumentException naming the offending value. Replace both with orElseThrow.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes FeatureProvider.Feature.of(String) in Recon to throw IllegalArgumentException for unknown feature names by replacing a dead Optional.get()/null-check sequence with orElseThrow, and adds a unit test to validate the behavior.
Changes:
- Updated
FeatureProvider.Feature.of(String)to useorElseThrow(IllegalArgumentException)when no matching feature is found. - Added
TestFeatureProviderto assert both successful lookup for known feature names and exception type/message content for unknown names.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/FeatureProvider.java | Replaces Optional.get() with orElseThrow so unknown feature names produce IllegalArgumentException instead of NoSuchElementException. |
| hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/types/TestFeatureProvider.java | Adds unit coverage for Feature.of(...) for both known and unknown feature name paths. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
echonesis
approved these changes
Aug 31, 2026
echonesis
left a comment
Contributor
There was a problem hiding this comment.
Thanks @henry3260 for the patch.
Overall, LGTM.
Just leave a nit.
The test lives in the same package as FeatureProvider, so the nested enum can be qualified through its outer class instead of imported.
chungen0126
self-requested a review
August 31, 2026 09:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
FeatureProvider.Feature.of(String)usedOptional.get()followed by a null check.Optional.get()never returns null, so the check was dead code and an unknownfeature name threw
NoSuchElementExceptioninstead ofIllegalArgumentException.Replaced with
orElseThrow.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-16351
How was this patch tested?
New unit test
TestFeatureProvider.