Skip to content

Removing nodes from association group will add them if none exist #52

Description

@mbbush

I was reading through the code to try to learn more about how association groups work, and I found what appears to be a bug in the 4-in-1 sensor driver. I didn't look to see if the same bug is present in other drivers as well.

state."desiredAssociation${group}" = nodes

If state."desiredAssociation${group}" is null, the condition at the beginning of the function which seems designed to avoid a null pointer exception is assuming that the method was called with an attempt to add nodes, not remove them. That's probably true, but not necessarily; you can never fully predict what the user will try to do. As a consumer of the code, I find this behavior counter to what I'd expect. I'd expect an attempt to remove nodes from a null list to either be a no-op or an error.

I think it would be really easy to fix this to be a no-op, using the groovy "elvis" operator ?:. Just replace the entire method body with this:

        switch (action) {
            case 0:
                state."desiredAssociation${group}" = state."desiredAssociation${group}" ?: [] - nodes
            break
            case 1:
                state."desiredAssociation${group}" = state."desiredAssociation${group}" ?: [] + nodes
            break
        }

Note: I haven't tested this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions