I have an observable list which needs to be validated. I used following snippet for validating this observable.
WritableList myList = new WritableList(realm...);
...
...
MultiValidator listValidtor = new MultiValidator() {
protected IStatus validate() {
if (myList.isEmpty()) {
return new Status(IStatus.ERROR....);
}
return ValidationStatus.ok();
}
};
bindingContext.addValidationStatusProvider(listValidtor);
...
...
I then have a code which attaches to validation status observables.
Problem I see is this: When MultiValidator.getValidationStatus() method is called for the first time it runs validation for first time using ObservableTracker.runAndMonitor.
After that it fetches all observables and adds them to a list. Now this is the list of observables which were found when running validate() method. In my case this results to a list containing only one observable, which is myList.
As a precautionary measure MultiValidator removes any internal observables which it uses from the list in order to avoid dependency loop.
Here is the issue. It maintains a observable named "targets' which is also a WritableList. Apparently this list is empty in the beginning. The code to remove internal observables from the list apparently removes myList because two empty lists are considered equal.
This is a snippet of revalidate() method in MultiValidator.
// myList is added to newTargets
List newTargets = new ArrayList(Arrays.asList(dependencies));
targets.retainAll(newTargets);
newTargets.removeAll(targets);
newTargets.remove(validationStatus);
newTargets.remove(unmodifiableValidationStatus);
// Even though targets is not myList it gets removed because
// Two empty list's equals method return true.
***newTargets.remove(targets);***
newTargets.remove(unmodifiableTargets);
newTargets.remove(models);
Is this a known issue? Or am I doing anything wrong.