Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDefaultRegistry that does not throw #1140

Merged
merged 1 commit into from
Jun 14, 2017

Conversation

ellisjoe
Copy link
Contributor

No description provided.

@ellisjoe
Copy link
Contributor Author

In library code I'd like to avoid using exceptions for control flow. Currently I have to write something like:

    private static MetricRegistry getMetricRegistry() {
        try {
            return SharedMetricRegistries.getDefault();
        } catch (IllegalStateException e) {
            return new MetricRegistry();
        }
    }

Ideally this method would return an Optional and I could then simplify the above to SharedMetricRegistries.getDefault().orElseGet(MetricRegistry::new), but it looks like metrics still supports Java 7.

@arteam arteam merged commit ccc61e3 into dropwizard:3.2-development Jun 14, 2017
@arteam
Copy link
Member

arteam commented Jun 14, 2017

LGTM! Thank you for the contribution!

I think we could provide a similar method for SharedHealthCheckRegistries too.

@jplock jplock added this to the 3.2.3 milestone Jun 14, 2017
@ellisjoe ellisjoe deleted the jellis/defaultRegistry branch June 15, 2017 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants