Skip to content

Builder.connect(): return the connection when it succeeds (check was inverted) - #37

Open
SanniniciStyle wants to merge 1 commit into
MuntashirAkon:masterfrom
SanniniciStyle:fix/builder-connect
Open

SanniniciStyle wants to merge 1 commit into
MuntashirAkon:masterfrom
SanniniciStyle:fix/builder-connect

Conversation

@SanniniciStyle

Copy link
Copy Markdown

Disclosure: this was found while building WatchSync with heavy AI assistance (Claude Code — "vibe coding", if you like). We work carefully: everything below was verified with the included unit test, but please review it with that in mind.

Both AdbConnection.Builder.connect() overloads have the check inverted:

if (adbConnection.connect()) {
    throw new IOException("Unable to establish a new connection.");
}
return adbConnection;

so a successful connection throws, and a failed one is returned. Now if (!...), and the failed connection is closed before throwing (it was leaked).

AdbConnectionBuilderTest connects to a minimal plain-text adbd on localhost that accepts at once:

Before: java.io.IOException: Unable to establish a new connection.  Tests run: 1, Failures: 1
After:  OK (1 test)

Both Builder.connect() overloads threw "Unable to establish a new
connection" when connect() returned true, and returned the connection when
it failed. The check is now the right way round, and a failed connection is
closed before throwing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant