Hit a Snag! possible bug?!?


(Stuart Buchanan) #1

ok so what i am wanting to do is pretty simple.

I have two arrays, one called children and the other called selectedNameList

children contains the following [Home, Workshop]

and

selectedNameList contains [Home]

so when i run the following
children.removeAll{selectedNameList.contains(it)}

I then look at the children and it still contains [Home, Workshop]

if i run identical code directly in a groovy console, the value of children is changed to [Workshop]…any ideas? headscratching!!!


(Larry) #2

what is it… are you sure it is the same case… groovy is case sensitive you make need to convert to lower case


(Stuart Buchanan) #3

The array is absolutely the same case. I have checked and re-checked. It just does not work in the smart app but absolutely does in a groovy console


(Larry) #4

print out what the variable it contains with starts round it… it may have a control character or something in it.


(Stuart Buchanan) #5

That in the first post is a copy and paste from the logging pane. I have logged both arrays to debug logging and compared. They are identical in case without any control characters.

I spent hours trying and carefully comparing. Has anyone else got this removeAll method working in ST? It just doesn’t work in multiple tests and I performed.


(Jim Anderson) #6

Do both lists contain elements of the same type? Wondering if it could look like a string but really be an object in there and you’re just seeing the toString() in the logs.

If in a SmartApp the following code doesn’t result in [bar], then we can say there’s a problem with the SmartThings Groovy:

​def list1 = ['foo', 'bar']
def list2 = ['foo']

list1.removeAll{list2.contains(it)}

log.debug list1​​​​​​​​​​​ // -> [bar]​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

If it does produce [bar], you might want to look more at what is in the two lists, or post more code to show how they are getting populated.


(Stuart Buchanan) #7

Jim,

Thanks for your help…i do feel a bit sheepish now. I was convinced I got the first array by calling the object.name in my code, however you were correct that I was just calling the object when I checked after reading your post.

Cheers for that as I could not see the wood for the trees


(Jim Anderson) #8

Yeah, one of the benefits of dynamic languages is you don’t have to litter your code with typing information… but the downside is that types still matter, and it’s not always clear what type your dealing with :slight_smile: