[
https://issues.apache.org/jira/browse/SOLR-13017?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Charles Sanders updated SOLR-13017:
-----------------------------------
Component/s: SolrJ
> SolrInputField.setValue method should not use supplied collection as backing
> value.
> -----------------------------------------------------------------------------------
>
> Key: SOLR-13017
> URL: https://issues.apache.org/jira/browse/SOLR-13017
> Project: Solr
> Issue Type: Improvement
> Security Level: Public(Default Security Level. Issues are Public)
> Components: SolrJ
> Reporter: Charles Sanders
> Priority: Minor
> Attachments: SOLR-13017.patch
>
>
> The setValue method in SolrInputField takes an argument of Object. If the
> supplied object is a collection, then the collection is used as the backing
> value for the field. This can cause unexpected results when the collection
> is used to initialize two or more different fields.
> Consider the example where a list of values 'a', 'b', 'c' is used to
> initialize two fields in a SolrInputDocument.
> {noformat}
> List<String> lst = new ArrayList<>();
> lst.add("a");
> lst.add("b");
> lst.add("c");
>
> SolrInputDocument sid = new SolrInputDocument();
> sid.addField("alpha", lst);
> sid.addField("beta", lst);
> .
> . {add more fields to doc}
> .
> sid.addField("beta", "blah"); // add another value to field 'beta'
> {noformat}
> Because the same list is used to initialize both fields 'alpha' and 'beta',
> they not only contain the same values, but point to the same instance of the
> list. Therefore, if an additional value is added to one of the fields, both
> will contain the value.
> In the example provided, the user would expect field 'alpha' to contain
> values 'a', 'b', 'c'. While field 'beta' should contain fields 'a', 'b', 'c'
> and 'blah'. But that is not the case. Both fields point to the same
> instance of the list, so if a new value is added to either field, the list is
> updated and both fields will contain the same values ('a', 'b', 'c', 'blah').
> This is not a bug, but the intended logic of the method based on the method
> comment.
> {noformat}
> /**
> * Set the value for a field. Arrays will be converted to a collection. If
> * a collection is given, then that collection will be used as the backing
> * collection for the values.
> */
> {noformat}
> This jira is a request to improve the logic of the method by not using the
> supplied collection as the backing value for the field. But rather, create a
> new collection and add the values from the supplied collection to the new
> collection. This way the field is not backed by the actual instance of the
> supplied collection, but its values only.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]