An operation AddEntryToMultivaluedProperty generates an error

The operation AddEntryToMultivaluedProperty generates the error in the method “run”. There is a problem in the line:

List<Serializable> array = p.getValue() != null ? Arrays.asList((Serializable[]) p.getValue()) : null;

It returns an exception:

Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to [;

In general, the problem is casting ArrayList returned by p.getValue() to Serializable[].


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs=""
<xs:include schemaLocation="base.xsd" />
<xs:element name="industries" type="nxs:stringList"/>

Document definition:

<?xml version="1.0" encoding="UTF-8"?>
<component name="org.nuxeo.mytest.default.types">
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
<schema name="myschema" prefix="myschema" src="schemas/myschema.xsd" />
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
<doctype name="MyDocument" extends="Document">
<schema name="common" />
<schema name="dublincore"/>
<schema name="uid"/>
<schema name="myschema" />
<extension target="org.nuxeo.ecm.core.lifecycle.LifeCycleService" point="types">
<type name="MyDocument">default</type>
<extension target="org.nuxeo.ecm.platform.types.TypeService" point="types">
<type id="MyDocument">
<layouts mode="any">
<layouts mode="edit">
<layouts mode="view">
<type id="Folder">

PHP code:

$doc["industries"] = "electrical";
$result = $session->newRequest("AddEntryToMultivaluedProperty")
->set('input', 'doc:'.$mydoc->getPath())
->set('params', 'xpath', 'myschema:industries')
->set('params', 'value', $doc["industries"])
0 votes

1 answers



p.getValue() should always return an array when p is a multi-value property. What is your property exactly?

It is nxs:stringList, so p.getValue() returns new ArrayList<String>().

It works in my tests. Nuxeo normalizes simples lists to arrays very early. The following test, modified from TestSQLRepositoryProperties, succeeds:

public void testStringArray() throws Exception {
    String[] values = { "foo", "bar" };
    doc.setPropertyValue("tp:stringArray", values);
    // doc.setPropertyValue("tp:stringArray", (Serializable) Arrays.asList(values)); // works too
    assertTrue(Arrays.equals(values, (Object[]) doc.getPropertyValue("tp:stringArray")));
    doc = session.saveDocument(doc);
    assertTrue(Arrays.equals(values, (Object[]) doc.getPropertyValue("tp:stringArray")));

Where tp:stringArray is defined as:

<xs:element name="stringArray" type="nxs:stringArrayType" />
<xs:simpleType name="stringArrayType">
  <xs:list itemType="xs:string" />
0 votes

Yes, it works, but it is not the same case. Could you try call the operation ? You can also try execute the equivalent code: List&lt;Serializable&gt; array = Arrays.asList((Serializable[]) new ArrayList&lt;String&gt;());

I understand that you're saying that p.getValue() returns an ArrayList but what I'm saying is that should not be the case and it does not happen in unit tests. Please provide a reproduction case so that we can understand what is happening.

I checked it in debugger that it crashes in the line i wroted. The same means the error description, but as you wish I provide the code.