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 1 commit into from Jun 14, 2017


Copy link

No description provided.

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
Copy link

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
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants