Skip to content

Commit 531f958

Browse files
Fixed spotbugs null check warnings
1 parent 7af34c0 commit 531f958

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/item/node/DefaultNodeItemFactory.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -146,42 +146,45 @@ protected Map<QName, IFlagNodeItem> generateFlags(@NonNull IModelNodeItem<?, ?>
146146
INamedModelInstanceAbsolute namedInstance = (INamedModelInstanceAbsolute) instance;
147147

148148
Object instanceValue = namedInstance.getValue(parentValue);
149-
150-
// the item values will be all non-null items
151-
Stream<? extends Object> itemValues = namedInstance.getItemValues(instanceValue).stream();
152-
AtomicInteger index = new AtomicInteger(); // NOPMD - intentional
153-
List<IModelNodeItem<?, ?>> items = itemValues.map(itemValue -> {
154-
assert itemValue != null;
155-
return newModelItem(namedInstance, parent, index.incrementAndGet(), itemValue);
156-
}).collect(Collectors.toUnmodifiableList());
157-
retval.put(namedInstance.getXmlQName(), items);
149+
if (instanceValue != null) {
150+
// the item values will be all non-null items
151+
Stream<? extends Object> itemValues = namedInstance.getItemValues(instanceValue).stream();
152+
AtomicInteger index = new AtomicInteger(); // NOPMD - intentional
153+
List<IModelNodeItem<?, ?>> items = itemValues.map(itemValue -> {
154+
assert itemValue != null;
155+
return newModelItem(namedInstance, parent, index.incrementAndGet(), itemValue);
156+
}).collect(Collectors.toUnmodifiableList());
157+
retval.put(namedInstance.getXmlQName(), items);
158+
}
158159
} else if (instance instanceof IChoiceGroupInstance) {
159160
IChoiceGroupInstance choiceInstance = (IChoiceGroupInstance) instance;
160161

161162
Object instanceValue = choiceInstance.getValue(parentValue);
162-
163-
Map<INamedModelInstanceGrouped, List<Object>> instanceMap = choiceInstance.getItemValues(instanceValue).stream()
164-
.map(item -> {
165-
assert item != null;
166-
INamedModelInstanceGrouped itemInstance = choiceInstance.getItemInstance(item);
167-
return Map.entry(itemInstance, item);
168-
})
169-
.collect(Collectors.groupingBy(
170-
entry -> entry.getKey(),
171-
LinkedHashMap::new,
172-
Collectors.mapping(entry -> entry.getValue(), Collectors.toUnmodifiableList())));
173-
174-
for (Map.Entry<INamedModelInstanceGrouped, List<Object>> entry : instanceMap.entrySet()) {
175-
INamedModelInstanceGrouped namedInstance = entry.getKey();
176-
assert namedInstance != null;
177-
178-
AtomicInteger index = new AtomicInteger(); // NOPMD - intentional
179-
List<IModelNodeItem<?, ?>> items = entry.getValue().stream()
180-
.map(itemValue -> {
181-
assert itemValue != null;
182-
return newModelItem(namedInstance, parent, index.incrementAndGet(), itemValue);
183-
}).collect(Collectors.toUnmodifiableList());
184-
retval.put(namedInstance.getXmlQName(), items);
163+
if (instanceValue != null) {
164+
Map<INamedModelInstanceGrouped, List<Object>> instanceMap
165+
= choiceInstance.getItemValues(instanceValue).stream()
166+
.map(item -> {
167+
assert item != null;
168+
INamedModelInstanceGrouped itemInstance = choiceInstance.getItemInstance(item);
169+
return Map.entry(itemInstance, item);
170+
})
171+
.collect(Collectors.groupingBy(
172+
entry -> entry.getKey(),
173+
LinkedHashMap::new,
174+
Collectors.mapping(entry -> entry.getValue(), Collectors.toUnmodifiableList())));
175+
176+
for (Map.Entry<INamedModelInstanceGrouped, List<Object>> entry : instanceMap.entrySet()) {
177+
INamedModelInstanceGrouped namedInstance = entry.getKey();
178+
assert namedInstance != null;
179+
180+
AtomicInteger index = new AtomicInteger(); // NOPMD - intentional
181+
List<IModelNodeItem<?, ?>> items = entry.getValue().stream()
182+
.map(itemValue -> {
183+
assert itemValue != null;
184+
return newModelItem(namedInstance, parent, index.incrementAndGet(), itemValue);
185+
}).collect(Collectors.toUnmodifiableList());
186+
retval.put(namedInstance.getXmlQName(), items);
187+
}
185188
}
186189
}
187190

0 commit comments

Comments
 (0)