Skip to content

Commit a13c37c

Browse files
authored
Fix NullPointerException from runHistoryExtraction (#189)
- In traverseTree (UpStreamEventsHandler), getRulesForEvent returned null if it couldn't find any rule, this fix makes sure it doesn't happen if it cant find any rule
1 parent 49ba420 commit a13c37c

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/main/java/com/ericsson/ei/handlers/UpStreamEventsHandler.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
package com.ericsson.ei.handlers;
1616

17-
import com.ericsson.ei.erqueryservice.ERQueryService;
18-
import com.ericsson.ei.erqueryservice.SearchOption;
19-
import com.ericsson.ei.rules.RulesHandler;
20-
import com.ericsson.ei.rules.RulesObject;
21-
import com.fasterxml.jackson.databind.JsonNode;
22-
2317
import org.slf4j.Logger;
2418
import org.slf4j.LoggerFactory;
2519
import org.springframework.beans.factory.annotation.Autowired;
2620
import org.springframework.http.ResponseEntity;
2721
import org.springframework.stereotype.Component;
2822

23+
import com.ericsson.ei.erqueryservice.ERQueryService;
24+
import com.ericsson.ei.erqueryservice.SearchOption;
25+
import com.ericsson.ei.rules.RulesHandler;
26+
import com.ericsson.ei.rules.RulesObject;
27+
import com.fasterxml.jackson.databind.JsonNode;
28+
2929
/**
3030
* The Class UpStreamEventsHandler.
3131
*/
@@ -86,13 +86,13 @@ public void runHistoryExtractionRulesOnAllUpstreamEvents(String aggregatedObject
8686
/**
8787
* Traverses the tree from ER. The tree is defined as an array of either an
8888
* event or a list of events. E.g:
89-
*
89+
*
9090
* <pre>
9191
* [A, [B, C, [D, E]], [F, [N, [G, H]]], [I, [J, [K, L, [M]]]]]
9292
* </pre>
93-
*
93+
*
9494
* Where the corresponding tree looks like this:
95-
*
95+
*
9696
* <pre>
9797
* A -> B -> C -> D -> E -> F -> N -> G -> H -> I -> J -> K -> L -> M
9898
* </pre>
@@ -116,8 +116,9 @@ private void traverseTree(final JsonNode jsonArray, final String aggregatedObjec
116116
// start collecting history
117117
RulesObject rules = rulesHandler.getRulesForEvent(parent.toString());
118118

119-
np = historyExtractionHandler.runHistoryExtraction(aggregatedObjectId, rules, parent.toString(),
120-
pathInAggregatedObject);
119+
if (rules != null) {
120+
np = historyExtractionHandler.runHistoryExtraction(aggregatedObjectId, rules, parent.toString(), pathInAggregatedObject);
121+
}
121122
}
122123
}
123124

@@ -126,8 +127,10 @@ private void traverseTree(final JsonNode jsonArray, final String aggregatedObjec
126127
if (jsonArray.get(i).isObject()) {
127128
String event = jsonArray.get(i).toString();
128129
RulesObject rules = rulesHandler.getRulesForEvent(event);
129-
prevNp = historyExtractionHandler.runHistoryExtraction(aggregatedObjectId, rules, event,
130-
pathInAggregatedObject);
130+
131+
if (rules != null) {
132+
np = historyExtractionHandler.runHistoryExtraction(aggregatedObjectId, rules, event, pathInAggregatedObject);
133+
}
131134
} else {
132135
// if we have prevNp then we should use that because it is the
133136
// "parent" of the list we are now going to

0 commit comments

Comments
 (0)