Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

The MessageHandler should not return null but throw a DBusException #1

@swiesend

Description

@swiesend

My new MessageHandler avoids returning null on my 2.0.0 branch as this only leads to problems, if the case is not handled properly.

public Object[] send(String service, String path, String iface, String method, String signature, Object... args) {
try {
org.freedesktop.dbus.messages.Message message = new MethodCall(
service,
path,
iface,
method, (byte) 0, signature, args);
connection.sendMessage(message);
org.freedesktop.dbus.messages.Message response = ((MethodCall) message).getReply(2000L);
log.trace(response.toString());
if (response instanceof org.freedesktop.dbus.errors.Error) {
throw new DBusException(response.getName() + ": " + response.getParameters()[0]);
}
Object[] parameters = response.getParameters();
log.debug(Arrays.deepToString(parameters));
return parameters;
} catch (DBusException e) {
log.error(e.toString(), e.getCause());
}
return null;
}

see: https://github.com/swiesend/secret-service/blob/c7399ea1f2d6031158a64a0459a066a35c7f9cbf/src/main/java/org/freedesktop/secret/handlers/MessageHandler.java#L34-L75

see also: swiesend/secret-service#6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions