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

fixed throwing behavior in daemonConfig #179

Merged
merged 6 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -101,6 +101,11 @@ private boolean setUDPAndTCPAddress(@Nullable String addr, boolean ignoreInvalid
boolean result = false;
try {
result = processAddress(addr);

if (!result) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need to check ignoreInvalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, because the exception will always be caught and then ignoreInvalid is checked in the catch block. If you think there's a more idiomatic way of doing this I'd be open to it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah didn't notice it - it's a bit weird to throw and immediately catch an exception. Outside of the try block having this with if (!result && !ignoreInvalid) throw might be more readable, but it's marginable at best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually just did a bigger refactor and made the processAddress method void, and just had it throw instead of return false. IMO this improved readability in both the setUDPandTCPAddress and processAddress methods, let me know what you think.

throw new IllegalArgumentException("Invalid value for agent address: " + addr
+ ". Value must be of form \"ip_address:port\" or \"tcp:ip_address:port udp:ip_address:port\".");
}
} catch (SecurityException | IllegalArgumentException e) {
if (ignoreInvalid) {
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,10 @@ public void testShouldThrowOnInvalidRuntimeConfig() {
DaemonConfiguration config = new DaemonConfiguration();
config.setDaemonAddress("0.0.0.1");
}

@Test(expected = IllegalArgumentException.class)
public void testShouldThrowOnReallyInvalidRuntimeConfig() {
DaemonConfiguration config = new DaemonConfiguration();
config.setDaemonAddress("Not an address");
}
}