Skip to content

DBus.getConnection() throws RuntimeException #128

Closed

Description

@infeo

This is a question.

To establish a connection to the DBus, one has to call DBus.getConnection(DBusBusType _bustype) throws DBusException (or one its sibling methods.

Within this method, at two spots a RuntimeExeption is thrown instead of the expected DBusException:

if (Util.isEmpty(sessionAddress)) {
throw new RuntimeException("Cannot Resolve Session Bus Address");
}

and
} catch (DBusException _ex) {
throw new RuntimeException("Cannot Resolve Session Bus Address", _ex);
}

My question is now: Why?
There is already an expected/ checked exception which could be used, namely the DBusException. This leads to errors in downstream libraries not anticipating the undocumented exceptions.

Activity

  1. hypfvieh commented on Jan 27, 2021

    @hypfvieh
    Owner

    The reason is, that the method passes Supplier<String> to another method. These Suppliers are created using a Lambda expression, which are not allowed to throw any checked exception.

    I agree that this is not a really good solution. I will change that in the next version, removing the Supplier stuff (does not help or make any sense here at all). I will then throw a DBusConnectionException which is a new exception derived from DBusException, so any existing code should work fine.

  2. added a commit that references this issue on Jan 27, 2021
  3. overheadhunter commented on Feb 11, 2021

    @overheadhunter

    The reason is, that the method passes Supplier<String> to another method. These Suppliers are created using a Lambda expression, which are not allowed to throw any checked exception.

    Just fyi, this is not true.

    @FunctionalInterface
    interface ThrowingSupplier<T> {
        T get() throws Exception;
    }
    
    // ...
    
    ThrowingSupplier<String> foo = () -> { throw new Exception(); } // runs just fine
  4. hypfvieh commented on Feb 11, 2021

    @hypfvieh
    Owner

    Yes it would be allowed, if it would use a custom ThrowingSupplier, but it doesn't.
    Therefore, throwing anything else than RuntimeException is not possible.

    Anyways, it also doesn't make any sense to me to comment on already fixed issues.
    As you might have seen I removed the Supplier stuff completely, so no need for another solution here

  5. overheadhunter commented on Feb 11, 2021

    @overheadhunter

    if it would use a custom ThrowingSupplier, but it doesn't

    It was only used in a private method, therefore a custom supplier would be easy to use.

    Anyways, it also doesn't make any sense to me to comment on already fixed issues.
    As you might have seen I removed the Supplier stuff completely, so no need for another solution here

    I saw it the moment I checked out the code. If the issue had been closed, I would have known this is already fixed. So choose your words carefully here. Didn't mean to hurt your feelings...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions