hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

Failed to construct outgoing method call: Primative array being sent as non-primative array. #8

Closed bertrik closed 6 years ago

bertrik commented 6 years ago

I'm happy to see the original dbus-java library being continued in this library and seeing active development on it. Can you give me your thoughts on the following:

I sometimes get an exception like this one, when doing a method call from Java to a C application: "org.freedesktop.dbus.exceptions.DBusExecutionException: Failed to construct outgoing method call: Primative array being sent as non-primative array." The method I invoke, looks like this: "int frameTransmit(byte[] frame);" I'm a bit puzzled because this only happens ocassionally, not consistently. I'm starting to suspect some kind of multi-threading issues perhaps.

The exception message appears to originate in Message.java#683. As I understand this happens before invoking the remote method, when the signature of an array argument to the method to be called is checked. Apparently it cannot find a specifier for a primitive type in this signature.

Could this indeed be some kind of multi-threading race condition? In a future version, can you perhaps update the exception message to include the offending type specifier in the signature? Also perhaps update the spelling of the word primitive?

hypfvieh commented 6 years ago

Hmm... I'm not sure wether it is a race condition or some other kind of bug. Most of the code is still like it was ten years ago. I just added some generics.

Line 683 in Message.java is a type cast from List<?> to Object[], it is in deed an array of Object, so a cast to a primitive array is not possible. I wonder why it is getting to that line. When you use a byte[], data should not be a List<?> instance.

To get the root cause from all of this, can you please post the complete stacktrace? Sample code would also be great, but the stacktrace will also help a lot.

bertrik commented 6 years ago

I mean it might be some kind of race/multithreading problem in my own code.

Line 683 in my Message.java (from release 2.7.4 not the git version) shows the exception: throw new MarshallingException(t("Primative array being sent as non-primative array."));

I don't have much of a stacktrace. This is what I have (please note this is from release 2.7.4): org.freedesktop.dbus.exceptions.DBusExecutionException: Failed to construct outgoing method call: Primative array being sent as non-primative array. at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:134) at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:234) at com.sun.proxy.$Proxy13.frameTransmit(Unknown Source) at nl.technolution.flowmeter.dbus.DbusGdcModule.sendFrame(DbusGdcModule.java:56)

hypfvieh commented 6 years ago

Race condition in your code is also possible :)

I've made a small test on my system using a DBus server written with dbus-java and a client also with dbus-java, sending around 100000 messages in a row as (primitive) byte array without any kind of DbusException.

Also it does not make sense to me, that it fails in line 683. For the code it looks like your data object given to the method is of type List.

I can only imagine two possible causes:

bertrik commented 6 years ago

Are we looking at the same code?

My Message.java line 683 says throw new MarshallingException(t("Primative array being sent as non-primative array."));

This is from dbus-java-2.7.4.jar

hypfvieh commented 6 years ago

Sorry I looked in a newer version.

Anyways... the given data object seems to be an array of a primitive type, but not of any type handled in the switch statement.

I can't help here. You should try to debug this part, so you get an idea which type is used here (check what ArgumentType sigb[i] contains).