Skip to content

Commit 001acbd

Browse files
committed
Return empty maps from feature getters
Ensure getters in FeaturesProperties return java.util.Collections.emptyMap() when underlying fields are null to avoid returning null and potential NPEs. Adds a static import for emptyMap and applies the change to getAbstract() and getNamed() methods.
1 parent 8b18437 commit 001acbd

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/actuator/FeaturesProperties.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Map;
2525

2626
import static io.microsphere.spring.cloud.client.actuator.constants.FeaturesConstants.PROPERTY_NAME_PREFIX;
27+
import static java.util.Collections.emptyMap;
2728

2829
/**
2930
* The {@link ConfigurationProperties} for {@link FeaturesEndpoint}
@@ -44,6 +45,9 @@ public void setAbstract(Map<String, List<String>> _abstract) {
4445
}
4546

4647
public Map<String, List<String>> getAbstract() {
48+
if (_abstract == null) {
49+
return emptyMap();
50+
}
4751
return _abstract;
4852
}
4953

@@ -52,6 +56,9 @@ public void setNamed(Map<String, Map<String, String>> named) {
5256
}
5357

5458
public Map<String, Map<String, String>> getNamed() {
59+
if (named == null) {
60+
return emptyMap();
61+
}
5562
return named;
5663
}
5764
}

0 commit comments

Comments
 (0)