Can't return a empty List
Submitted by Pawel Szklarz
Assigned to Matthew Johnson @mjj29
Description
Testing the implementation of:
<method name="getAllProcess">
</method>
I am returning a empty list.
The client gets the error:
org.freedesktop.dbus.exceptions.DBusExecutionException: Error Executing Method com.pmsoft.eserv.nec.core.bis.ProcessRejestry.getAllProcess: 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) .......
In the server site, I get exception java.lang.ArrayIndexOutOfBoundsException: 1
on class org.freedesktop.dbus.Message, method public void append(String sig, Object... data) throws DBusException line 777: for (int i = 0; i < sigb.length; i++) { if (Debug.debug) Debug.print(..... i = appendone(sigb, i, data[j++]); <<<< here }
Debugint dbus-java library i found that in class org.freedesktop.dbus.Message, method "appendone", starting from line 624, the follow code generates the real problem
} else if (data instanceof List) { Object[] contents = ((List) data).toArray(); int diff = i; ensureBuffers(contents.length*4); for (Object o: contents) diff = appendone(sigb, i, o); <<<not executed for empty list!!! i = diff; } else if....
For empty list, the marked code is not executed, so, diff is not calculated. In the case of "a(ssss)", diff should be 1+4. As a result, the return value from appenddone is 1 and not 5, and appenddone is executed one more time. data[2] gives the ArrayIndexOutOfBoundsException.
I am using dbus-java 2.6. In the git repositorium the code is the same.
The problem is solved for the "data instanceof Map" case with the code:
if (i == diff) {
// advance the type parser even on 0-size arrays.
Vector<Type>
temp = new Vector<Type>
();
byte[] temp2 = new byte[sigb.length-diff];
System.arraycopy(sigb, diff, temp2, 0, temp2.length);
String temp3 = new String(temp2);
int temp4 = Marshalling.getJavaType(temp3, temp, 1);
diff += temp4;
}
Using exacly the same code for the list case, the request is returning and the client gets a empty list.
Version: 1.2.x