Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBus.getConnection() throws RuntimeException #128

Closed
infeo opened this issue Jan 26, 2021 · 4 comments
Closed

DBus.getConnection() throws RuntimeException #128

infeo opened this issue Jan 26, 2021 · 4 comments

Comments

@infeo
Copy link

infeo commented Jan 26, 2021

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.

@hypfvieh
Copy link
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.

@overheadhunter
Copy link

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

@hypfvieh
Copy link
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

@overheadhunter
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants