Skip to content

Commit 844acad

Browse files
committed
Improve diagnostics when registration fails due to empty name
1 parent 2861889 commit 844acad

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

spring-boot-project/spring-boot-health/src/main/java/org/springframework/boot/health/registry/AbstractHealthContributorRegistry.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ abstract class AbstractHealthContributorRegistry<C, E> {
5151
this.nameValidators = List.copyOf(nameValidators);
5252
this.entryAdapter = entryAdapter;
5353
Assert.notNull(contributors, "'contributors' must not be null");
54-
contributors.keySet().forEach(this::verifyName);
54+
contributors.entrySet().forEach((entry) -> this.verifyName(entry.getKey(), entry.getValue()));
5555
this.contributors = Collections.unmodifiableMap(new LinkedHashMap<>(contributors));
5656
}
5757

5858
void registerContributor(String name, C contributor) {
5959
Assert.hasText(name, "'name' must not be empty");
6060
Assert.notNull(contributor, "'contributor' must not be null");
61-
verifyName(name);
61+
verifyName(name, contributor);
6262
synchronized (this.monitor) {
6363
Assert.state(!this.contributors.containsKey(name),
6464
() -> "A contributor named \"" + name + "\" has already been registered");
@@ -103,8 +103,9 @@ public E next() {
103103
};
104104
}
105105

106-
private void verifyName(String name) {
107-
Assert.state(StringUtils.hasText(name), "Contributor name must not be empty");
106+
private void verifyName(String name, C contributor) {
107+
Assert.state(StringUtils.hasText(name),
108+
() -> "Name for contributor '%s' must not be empty".formatted(contributor));
108109
if (!CollectionUtils.isEmpty(this.nameValidators)) {
109110
this.nameValidators.forEach((nameValidator) -> nameValidator.validate(name));
110111
}

0 commit comments

Comments
 (0)