Skip to content

Deprecate SocketAddress-related methods #1188

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

Merged
merged 1 commit into from
Sep 7, 2023
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
4 changes: 4 additions & 0 deletions driver-core/src/main/com/mongodb/ServerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ public int getPort() {
* Gets the underlying socket address
*
* @return socket address
* @deprecated Prefer {@link InetAddress#getByName(String)}
*/
@Deprecated
public InetSocketAddress getSocketAddress() {
try {
return new InetSocketAddress(InetAddress.getByName(host), port);
Expand All @@ -203,7 +205,9 @@ public InetSocketAddress getSocketAddress() {
* @return array of socket addresses
*
* @since 3.9
* @deprecated Prefer {@link InetAddress#getAllByName(String)}
*/
@Deprecated
public List<InetSocketAddress> getSocketAddresses() {
try {
InetAddress[] inetAddresses = InetAddress.getAllByName(host);
Expand Down
4 changes: 4 additions & 0 deletions driver-core/src/main/com/mongodb/UnixServerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ public UnixServerAddress(final String path) {
isTrueArgument("The path must end in .sock", path.endsWith(".sock"));
}

@SuppressWarnings("deprecation")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure why the warning also has to be suppressed here, but it complains if I don't

Copy link
Member

Choose a reason for hiding this comment

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

It's probably because of the -Xlint:deprecation lint: the method overrides a deprecated method.

@Deprecated
@Override
public InetSocketAddress getSocketAddress() {
throw new UnsupportedOperationException("Cannot return a InetSocketAddress from a UnixServerAddress");
}

/**
* @return the SocketAddress for the MongoD unix domain socket.
* @deprecated Prefer {@link UnixSocketAddress#UnixSocketAddress(String)}
*/
@Deprecated
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This one seems similar enough to also deprecate at the same time

public SocketAddress getUnixSocketAddress() {
return new UnixSocketAddress(getHost());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public boolean supportsAdditionalTimeout() {
return true;
}

@SuppressWarnings("deprecation")
@Override
public void openAsync(final AsyncCompletionHandler<Void> handler) {
isTrue("unopened", getChannel() == null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public void open() throws IOException {
handler.get();
}

@SuppressWarnings("deprecation")
@Override
public void openAsync(final AsyncCompletionHandler<Void> handler) {
Queue<SocketAddress> socketAddressQueue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public AsynchronousSocketChannelStream(final ServerAddress serverAddress, final
this.group = group;
}

@SuppressWarnings("deprecation")
@Override
public void openAsync(final AsyncCompletionHandler<Void> handler) {
isTrue("unopened", getChannel() == null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ final class ServerAddressWithResolver extends ServerAddress {
this.resolver = inetAddressResolver == null ? DEFAULT_INET_ADDRESS_RESOLVER : inetAddressResolver;
}

@SuppressWarnings("deprecation")
@Override
public InetSocketAddress getSocketAddress() {
if (resolver == null) {
Expand All @@ -60,6 +61,7 @@ public InetSocketAddress getSocketAddress() {
return getSocketAddresses().get(0);
}

@SuppressWarnings("deprecation")
@Override
public List<InetSocketAddress> getSocketAddresses() {
if (resolver == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void open() {
}
}

@SuppressWarnings("deprecation")
protected Socket initializeSocket() throws IOException {
Iterator<InetSocketAddress> inetSocketAddresses = address.getSocketAddresses().iterator();
while (inetSocketAddresses.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public UnixSocketChannelStream(final UnixServerAddress address, final SocketSett
this.address = address;
}

@SuppressWarnings("deprecation")
@Override
protected Socket initializeSocket() throws IOException {
return UnixSocketChannel.open((UnixSocketAddress) address.getUnixSocketAddress()).socket();
Expand Down