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
180 stars 72 forks source link

Sending signal with byte[] fails with verbose logging #247

Closed AsamK closed 7 months ago

AsamK commented 7 months ago

I have a signal defined, that contains a field with type byte[].

class Signal extends DBusSignal {

        private final byte[] groupId;

        public Signal(
                String objectpath,
                byte[] groupId
        ) throws DBusException {
            super(objectpath, groupId);
            this.groupId = groupId;
        }
}

Sending this connection.sendMessage(new Signal(...)) works fine, with normal log level. But when I set the log level to verbose, the sending fails.

The error seems to be in the code in LoggingHelper that tries to to serialize the the object to a string. It fails to cast a byte array (byte[], [B) to an object array (Object[], [Ljava.lang.Object;), which doesn't work. Primitive arrays can't be cast to an object array.

Error:

java.lang.ClassCastException: class [B cannot be cast to class [Ljava.lang.Object; ([B and [Ljava.lang.Object; are in module java.base of loader 'bootstrap')
        at org.freedesktop.dbus.utils.LoggingHelper.arraysVeryDeepStringRecursive(LoggingHelper.java:56)
        at org.freedesktop.dbus.utils.LoggingHelper.arraysVeryDeepString(LoggingHelper.java:34)
        at org.freedesktop.dbus.messages.Message.lambda$append$3(Message.java:882)
        at org.freedesktop.dbus.utils.LoggingHelper.logIf(LoggingHelper.java:76)
        at org.freedesktop.dbus.messages.Message.append(Message.java:882)
        at org.freedesktop.dbus.messages.DBusSignal.appendbody(DBusSignal.java:277)
        at org.freedesktop.dbus.connections.AbstractConnection.sendMessageInternally(AbstractConnection.java:1087)
        at org.freedesktop.dbus.connections.AbstractConnection$1.run(AbstractConnection.java:406)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1583)

Version: 4.3.1

hypfvieh commented 7 months ago

Will be fixed in 5.x and 4.3.2