cytomine / Cytomine-java-client

Cytomine Java client
Apache License 2.0
12 stars 14 forks source link

Bug with reference when we use collection.get(index) #20

Closed geektortoise closed 3 years ago

geektortoise commented 3 years ago

If a put some models in a Map or a List, there is odd behavior

for(int i =0;i< collection.size();i++) {
list.add(collection.get(i))
}

I guess it is a reference problem due to the fact that get(index) use this.modelInstance

Solution : clone it before return a model ?

loic911 commented 3 years ago

@geektortoise What do you mean by "odd behavior"? :) Do you mean that modifying the object in list.get(i) modify the object in collection.get(i) too (because same object)?

geektortoise commented 3 years ago

In this case, If I have collection = [model1, model2] after this loop, I got in list the value [model2, model2] More exactly, the flow is list = [] list = [model1] list = [model2,model2]

I would expect a [model1,model2] result