[
https://issues.apache.org/jira/browse/HDDS-16351?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated HDDS-16351:
----------------------------------
Labels: pull-request-available (was: )
> FeatureProvider.Feature.of throws NoSuchElementException instead of
> IllegalArgumentException
> --------------------------------------------------------------------------------------------
>
> Key: HDDS-16351
> URL: https://issues.apache.org/jira/browse/HDDS-16351
> Project: Apache Ozone
> Issue Type: Bug
> Components: Ozone Recon
> Reporter: Henry Chen
> Assignee: Henry Chen
> Priority: Minor
> Labels: pull-request-available
>
> {{FeatureProvider.Feature.of(String)}} uses {{Optional.get()}} and then
> null-checks the result:
> {{Feature featureEnum = Arrays.stream(Feature.values())
> .filter(feature -> feature.getFeatureName().equals(featureName))
> .findFirst().get();
> if (null == featureEnum) \{
> throw new IllegalArgumentException("Unrecognized value for Features enum: "
> + featureName);
> }}}
> {{Optional.get()}} never returns null, so the null check is dead code. For an
> unrecognized feature name the method throws a bare {{NoSuchElementException}}
> instead of the intended {{IllegalArgumentException}} naming the offending
> value.
> The method currently has no callers, so this is latent.
> Fix: use {{{}orElseThrow(() -> new IllegalArgumentException(...)){}}}, or
> remove the unused method.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]