removeAllElementValues bug

Post your questions and help other users.

Moderator: Martin

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

removeAllElementValues bug

Post by anuraag » 15 Oct 2018 02:56

I have created a flow.
Action init "Variable File List"
Then
script

Code: Select all

exclude=newList("/storage/emulated/0/Android");
removeElementValue(files, exclude);
but exclude list aren't removed.

If i use loop insted of removeAllElementValues it works.

http://automagic4android.com/flow.php?i ... df6685b337

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: removeAllElementValues bug

Post by Desmanto » 16 Oct 2018 02:46

the second line of script should be removeAllElementValues(files, exclude);
but I get it, you test the script several times.

This is such a peculiar bug. I have run your flow more than 80 times in several occassions, for probably more than 1 hour. Here are my finding :

1. Init Variable Files List to {files}, changing name of this variable, doesn't make different

Code: Select all

newfiles = copyList(files)
2 .the newfiles still inherit the same problem

Code: Select all

global_files = files
3. then try to remove from the glovar, same problem.

Code: Select all

for(i in files) addElement(newfiles)
4.the newfiles still inherit same problem.

5. Amazingly, create a newList()

Code: Select all

create = newList(
"/storage/emulated/0/Alarms",
"/storage/emulated/0/Android",
"/storage/emulated/0/Automagic",
"/storage/emulated/0/bluetooth",
"/storage/emulated/0/CallRecordings");

exclude=newList("/storage/emulated/0/Android");
removeAllElementValues(create, exclude);
//or
//removeElementValue(create, exclude[0]);
This will remove the /storage/emulated/0/Android. So the function works. Testing with other created list from script also work. But it won't work for the list created by the init variables files list and all its derivation.

6. Suprisingly, if we save the list element from the {files} itself, it works

Code: Select all

global_file = newList(files[1]); //save "/storage/emulated/0/Android"
in the next execution, if we call

Code: Select all

removeAllElementValues(files, global_file);
it works. So the {files} can only be removed value by using its own derivation, not by the list created by other script.

7. Use debug dialog, copy out the /storage/emulated/0/Android and paste it in script, still doesn't get removed. Only assigned directly just like point 6 will work

8. use debug dialog, show the {files} as JSON. Copy out all lines and put it as newList(). The new list match true to files, mean they are the same. But new list can be removed properly, while files can't.

9. Use encodeURL() on /storage/emulated/0/Android, get /storage/emulated/0/Android, result is %2Fstorage%2Femulated%2F0%2FAndroid. The same as the value assigned using script.

Code: Select all

a = exclude[0] == files[1]
10. It shows {a} is true, so actually it match. But why if they are the same already, we can't use removeElementValue() or removeAllElementValues()

11. iteration removal using index, removeElement() works

12. Use Execute command : ls -ad /storage/emulated/0/*
Then at script, parse the result into {files}

Code: Select all

files = removeElementValue(findAll(stdout, ".*"), '');
using the {files} from this parsing works fine. I can say that the list created by using script works fine.

13. Using Init Variable File List, and check Include file attributes. This will result in the {files} become nested list. If we remove from the nested list or the derived list from it, it works.

Code: Select all

filelist = newList()
for(i in files)
  addElement(filelist, i[0]);
or if we just remove directly from the files[1] (which is a list), also work.

So the culprit seems like action Init variable File List created a {files} list variable which has something that has extra attribute/char which is same and different at the same time. Same means the evaluation == will be true, but different because we can't use removeElementValue() or removeAllElementValues() on it.

This is even more mysterius than my invisible character at the BOM text file troubleshooting.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: removeAllElementValues bug

Post by anuraag » 16 Oct 2018 03:59

@Desmanto thanks for long testing. :thumbsup:

In my main script it is removeElementValues.

That only function made my flow to take 3 times more time. I thought script was working.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: removeAllElementValues bug

Post by Desmanto » 16 Oct 2018 15:36

I also use both functions, but perfom on list created inside script, hence not yet encounter this bug.
Both functions are very useful to remove duplicates or find differences in 2 different lists.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: removeAllElementValues bug

Post by Martin » 16 Oct 2018 19:03

It's a bug that removeAllElementValues does not properly work with the list provided with action Init Variable File List. This should be fixed in the next build.
Thanks for reporting!

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: removeAllElementValues bug

Post by Desmanto » 17 Oct 2018 17:38

Thanks for the quick fix. The latest 1.36.0 EAP version has fixed this bug.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: removeAllElementValues bug

Post by Martin » 19 Oct 2018 19:00

Thanks for testing & confirming!

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: removeAllElementValues bug

Post by anuraag » 21 Jul 2019 11:58

Encountered an another list type where removeAllElementValues doesn't work. Tried to recreate the bug with new flow without success. So far only workaround is to convert list to JSON and then use fromJSON before using removeAllElementValues.

Code: Select all

diff = removeAllElementValues(fromJSON(toJSON(list1)), fromJSON(toJSON(list2)))

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: removeAllElementValues bug

Post by Desmanto » 21 Jul 2019 17:53

@anuraag : What action produce the list? Can you give example so I can reproduce it? I have encounter the problem yet, but it can be happened already, but I don't know it. Because I also use removeAllElementValues() occassionally.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: removeAllElementValues bug

Post by anuraag » 22 Jul 2019 02:03

Ok finally after lots of attempt found the problem

Code: Select all

list1=newList(1,2,3,4);
list2=copyList(list1);
Then convert list1 to json and then convert it to list. Using this as i save my variable to text file.

Code: Select all

list1=fromJSON(toJSON(list1));
diff=removeAllElementValues(list1, list2);
diff should return empty list but returns 1,2,3,4.
toJSON and fromJSON somehow causing this.

Edit: another example

Code: Select all

map=newMapFromValues(1, 1, 2, 2, 3, 3, 4, 4);
map=fromJSON(toJSON(map));
list1=getMapValues(map);
list2=newList(1,2,3,4);
diff=removeAllElementValues(list1, list2);

Post Reply