markap14 commented on PR #6154:
URL: https://github.com/apache/nifi/pull/6154#issuecomment-1196788883
@thenatog that's a good catch. That code is very definitely wrong!
The `entityMap` here has a key of type `String` but this line of code:
```
Map<NodeIdentifier, ReportingTaskEntity> innerMap = entityMap.get(nodeId);
```
attempts to lookup a value for an object of type `NodeIdentifier` so it will
definitely always return `null`.
I think the bug here is that line should be:
```
Map<NodeIdentifier, ReportingTaskEntity> innerMap =
entityMap.get(nodeReportingTaskEntity.getId());
```
Now, given that we're using Java 8, this can actually be significantly
simplified by just changing this block of code:
```
Map<NodeIdentifier, ReportingTaskEntity> innerMap =
entityMap.get(nodeId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodeReportingTaskEntity.getId(), innerMap);
}
```
To the much simpler:
```
Map<NodeIdentifier, ReportingTaskEntity> innerMap =
entityMap.computeIfAbsent(nodeReportingTaskEntity.getId(), k -> new
HashMap<>());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]