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

Projects
None yet
3 participants
@ellisjoe
Contributor

ellisjoe commented Jun 14, 2017

No description provided.

@ellisjoe

This comment has been minimized.

Show comment
Hide comment
@ellisjoe

ellisjoe Jun 14, 2017

Contributor

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.

Contributor

ellisjoe commented Jun 14, 2017

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@arteam

This comment has been minimized.

Show comment
Hide comment
@arteam

arteam Jun 14, 2017

Member

LGTM! Thank you for the contribution!

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

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

@jplock jplock added the improvement label Jun 14, 2017

@ellisjoe ellisjoe deleted the ellisjoe:jellis/defaultRegistry branch Jun 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment