Closed awoSYS closed 3 years ago
@awoSYS Well, this is a documentation problem more than it is a bug. I should have used List#of()
rather than Arrays#asList()
, because the former provides stronger immutability guarantees than the latter (the List<T>
returned by Arrays#asList()
allows in-place modification via #set(index, newValue)
). Unless explicitly noted, all collections (List, Map, etc.) returned by Kalix methods are meant to always be immutable. That means that #retainAll()
will never work on a list returned by a generated or normal Kalix method. You should rather use list.stream().filter(..).toList()
if you want to filter a list.
Immutability is a way of reducing program complexity. If mutable references are never shared between objects, you never have to wonder what objects are able to modify them.
@emanuelpalm Yeah, good pointer to the advantages of immutability. However, in this case it's the ServiceQuery.oneUsing()
method (via ServiceQuery#updateAndValidateUsing()
) that tries to do retainAll()
on the list that's supposed to be immutable, right?
@awoSYS I didn't look carefully enough at the stack trace. You are right. I will fix it.
This bug is fixed in version 0.5.3, which will be on Maven Central in 10 minutes or so. Please reopen the issue if the problem would remain in the new version.
I'm using the kalix lib v0.5, in which I found a bug, which I think still exists in the current lib version. I'm doing this:
Where
provEnc
is of typeEncodingDescriptor
andprovTransp
is of typeTransportDescriptor
. This results in the following error:As far as I understand it, this is a result of trying to do
retainAll()
on aList
that's created by theServiceQuery#encodings(final EncodingDescriptor...)
method via this line:this.encodings = Arrays.asList(encodings);
. The corresponding line in the current lib version seems to be this one. TheList
created that way doesn't seem to supportretainAll()
andremove()
, see also this Stackoverflow post.Hope this helps.