fix(D-01): compact constructor defaults null componentConfigs to empty (RISK-004)
Add compact constructor to DataDrivenItemDefinition that defaults null componentConfigs to Map.of(). This makes the field guaranteed non-null, allowing removal of null checks in hasComponent() and DataDrivenItemRegistry.buildComponentHolders().
This commit is contained in:
@@ -105,8 +105,13 @@ public record DataDrivenItemDefinition(
|
|||||||
Map<ComponentType, JsonObject> componentConfigs
|
Map<ComponentType, JsonObject> componentConfigs
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
/** Compact constructor: default null componentConfigs to empty immutable map. */
|
||||||
|
public DataDrivenItemDefinition {
|
||||||
|
if (componentConfigs == null) componentConfigs = Map.of();
|
||||||
|
}
|
||||||
|
|
||||||
/** Check whether this definition declares a given component type. */
|
/** Check whether this definition declares a given component type. */
|
||||||
public boolean hasComponent(ComponentType type) {
|
public boolean hasComponent(ComponentType type) {
|
||||||
return componentConfigs != null && componentConfigs.containsKey(type);
|
return componentConfigs.containsKey(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,7 +185,6 @@ public final class DataDrivenItemRegistry {
|
|||||||
DataDrivenItemDefinition def = entry.getValue();
|
DataDrivenItemDefinition def = entry.getValue();
|
||||||
Map<ComponentType, IItemComponent> components =
|
Map<ComponentType, IItemComponent> components =
|
||||||
new EnumMap<>(ComponentType.class);
|
new EnumMap<>(ComponentType.class);
|
||||||
if (def.componentConfigs() != null) {
|
|
||||||
for (Map.Entry<ComponentType, JsonObject> compEntry :
|
for (Map.Entry<ComponentType, JsonObject> compEntry :
|
||||||
def.componentConfigs().entrySet()) {
|
def.componentConfigs().entrySet()) {
|
||||||
components.put(
|
components.put(
|
||||||
@@ -193,7 +192,6 @@ public final class DataDrivenItemRegistry {
|
|||||||
compEntry.getKey().create(compEntry.getValue())
|
compEntry.getKey().create(compEntry.getValue())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
holders.put(
|
holders.put(
|
||||||
entry.getKey(),
|
entry.getKey(),
|
||||||
components.isEmpty()
|
components.isEmpty()
|
||||||
|
|||||||
Reference in New Issue
Block a user