Skip to content

NPE when the contextObject does not exist in the tree #28

@mathieucarbou

Description

@mathieucarbou

This issue has been extracted from #27. See #27 for the full details

Would it be possible also to add a fix so that we do not have a NPE in the case the object of the query is not in the tree ?

I..e:

Instead of doing:

    TreeNode treeNode = ContextManager.nodeFor(contextObject);
    if(treeNode == null) {
      return;
    }

    Set<TreeNode> result = queryBuilder()
        .descendants()
        .filter(context(attributes(Matchers.<Map<String, Object>>allOf(
            hasAttribute("type", descriptor.getType()),
            hasAttribute("name", descriptor.getObserverName()),
            hasTags(descriptor.getTags())))))
        .filter(context(identifier(subclassOf(OperationStatistic.class))))
        .build().execute(Collections.singleton(treeNode));

We should be able to just do something like:

 Set<TreeNode> result = queryBuilder()
        .descendants()
        .filter(context(attributes(Matchers.<Map<String, Object>>allOf(
            hasAttribute("type", descriptor.getType()),
            hasAttribute("name", descriptor.getObserverName()),
            hasTags(descriptor.getTags())))))
        .filter(context(identifier(subclassOf(OperationStatistic.class))))
        .build().execute(Collections.singleton(ContextManager.nodeFor(contextObject)));

or:

        .build().execute(contextObject);

And the query system would just return an empty set of nodes because the queried objects are not there.

(related to Terracotta-OSS/terracotta-platform#263)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions