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

added checks for system-only DBus #4

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ public class KDEWalletKeychainAccess implements KeychainAccessProvider {
public KDEWalletKeychainAccess() {
ConnectedWallet wallet = null;
try {
DBusConnection conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
DBusConnection conn = null;
try {
conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
} catch (RuntimeException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBusConnection.getConnection throws a DBusException doesn't it? I'd suggest to catch that instead.

Copy link
Contributor Author

@Liboicl Liboicl Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can throw a DBusException on certain errors but in the case of a non-existent session DBus it is only throwing a RuntimeException as per this line
Caused by: java.lang.RuntimeException: Cannot Resolve Session Bus Address
Using a DBusException in place of it results in the same error as before and the catch is never executed. Maybe I should catch both, though?
There may be a better way to check before the exception is thrown... Let me look into it a bit more.

EDIT: I added in a more specific check in the new push and prettied the code up a bit, trying to conform to the other code. I also took out the stack trace output for the missing session DBus, as it isn't necessary when handled correctly. Let me know what your thoughts are on it.

EDIT 2: Sorry to keep editing, but looking at the source for dbus-java it should be throwing a DBusException. I'm not sure why it isn't in this case. I'm going to try to compile it myself and see how it handles.

if (e.getMessage() == "Cannot Resolve Session Bus Address") {
LOG.warn("SESSION DBus not found.");
}
}
if (conn == null) {
conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SYSTEM);
}
wallet = new ConnectedWallet(conn);
} catch (DBusException e) {
LOG.warn("Connecting to D-Bus failed.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public boolean isSupported() {
try (@SuppressWarnings("unused") SimpleCollection keyring = new SimpleCollection()) {
// seems like we're able to access the keyring.
return true;
} catch (IOException | RuntimeException e) {
} catch (IOException | ExceptionInInitializerError | RuntimeException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add the ExceptionInInitializerError here? I think secret-service throws an IOException if something goes wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's based upon the actual code running on my setup. With the Session DBus non-existent it threw an ExceptionInInitializerError upon running, so I just added it to the list so it marks it as not supported. Without that, it crashes similarly to the original issue, but with SecretService in the backtrace.

return false;
}
}
Expand Down