Skip to content

HDDS-16351. FeatureProvider.Feature.of throws NoSuchElementException instead of IllegalArgumentException - #11170

Open
henry3260 wants to merge 2 commits into
apache:masterfrom
henry3260:HDDS-16351
Open

HDDS-16351. FeatureProvider.Feature.of throws NoSuchElementException instead of IllegalArgumentException#11170
henry3260 wants to merge 2 commits into
apache:masterfrom
henry3260:HDDS-16351

Conversation

@henry3260

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

FeatureProvider.Feature.of(String) used Optional.get() followed by a null check.
Optional.get() never returns null, so the check was dead code and an unknown
feature name threw NoSuchElementException instead of IllegalArgumentException.
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.

…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.
Copilot AI lite review requested due to automatic review settings August 30, 2026 16:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 use orElseThrow(IllegalArgumentException) when no matching feature is found.
  • Added TestFeatureProvider to 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 echonesis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

3 participants