Skip to content

Commit

Permalink
Merge pull request #6295 from OpenNMS/jira/NMS-15806-metadata-excepti…
Browse files Browse the repository at this point in the history
…on-smoke

NMS-15806: fix some bounds-checking on possible null values
  • Loading branch information
Benjamin Reed authored Jun 30, 2023
2 parents 76dca7a + 45e4bd6 commit 5e83fab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected static ResourcePath toChildResourcePath(ResourcePath parent, String re
final String childEls[] = child.elements();
final String parentEls[] = parent.elements();

if (childEls.length <= parentEls.length) {
if (childEls == null || parentEls == null || childEls.length <= parentEls.length) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ private String getNodeCriteriaFromResource(CollectionResource resource) {

String nodeCriteria = null;
if (resource.getParent() != null) {
String[] resourcePathArray = resource.getParent().elements();
if (ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY.equals(resourcePathArray[0])
&& resourcePathArray.length == 3) {
// parent denotes nodeCriteria, form fs:fid
nodeCriteria = resourcePathArray[1] + ":" + resourcePathArray[2];
} else if (checkNumeric(resourcePathArray[0])) {
// parent denotes nodeId
nodeCriteria = resourcePathArray[0];
final String[] resourcePathArray = resource.getParent().elements();
if (resourcePathArray != null) {
if (ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY.equals(resourcePathArray[0])
&& resourcePathArray.length == 3) {
// parent denotes nodeCriteria, form fs:fid
nodeCriteria = resourcePathArray[1] + ":" + resourcePathArray[2];
} else if (checkNumeric(resourcePathArray[0])) {
// parent denotes nodeId
nodeCriteria = resourcePathArray[0];
}
}
}
return nodeCriteria;
Expand Down

0 comments on commit 5e83fab

Please sign in to comment.