Add null check in RefreshScopeHealthIndicator. Fixes #397. (#398)

This commit is contained in:
Ryan Baxter
2018-07-26 15:09:05 -04:00
committed by GitHub
parent 84659685d6
commit 57ab7ed469
2 changed files with 21 additions and 13 deletions

View File

@@ -45,19 +45,20 @@ public class RefreshScopeHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Builder builder) throws Exception {
Map<String, Exception> errors = new HashMap<>(this.scope.getIfAvailable().getErrors());
errors.putAll(this.rebinder.getErrors());
if (errors.isEmpty()) {
builder.up();
}
else {
builder.down();
if (errors.size() == 1) {
builder.withException(errors.values().iterator().next());
}
else {
for (String name : errors.keySet()) {
builder.withDetail(name, errors.get(name));
RefreshScope refreshScope = this.scope.getIfAvailable();
if(refreshScope != null) {
Map<String, Exception> errors = new HashMap<>(refreshScope.getErrors());
errors.putAll(this.rebinder.getErrors());
if (errors.isEmpty()) {
builder.up();
} else {
builder.down();
if (errors.size() == 1) {
builder.withException(errors.values().iterator().next());
} else {
for (String name : errors.keySet()) {
builder.withDetail(name, errors.get(name));
}
}
}
}

View File

@@ -81,4 +81,11 @@ public class RefreshScopeHealthIndicatorTests {
assertEquals(Status.DOWN, this.indicator.health().getStatus());
}
@Test
public void nullRefreshScope() {
ObjectProvider<RefreshScope> scopeProvider = mock(ObjectProvider.class);
BDDMockito.willReturn(null).given(scopeProvider).getIfAvailable();
assertEquals(Status.UP, this.indicator.health().getStatus());
}
}