Skip to content

Commit

Permalink
INTERNAL: Remove "/<unresolved>" from InetSocketAddress.toString() fo…
Browse files Browse the repository at this point in the history
…r upward compatibility on JDK 14+
  • Loading branch information
uhm0311 committed Nov 30, 2023
1 parent c11e912 commit a462101
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/main/java/net/spy/memcached/AddrUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.spy.memcached;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -56,4 +57,16 @@ public static List<InetSocketAddress> getAddresses(String s) {
public static InetSocketAddress getAddress(String s) {
return getAddresses(s).get(0);
}

public static String getSocketAddressString(SocketAddress addr) {
if (addr instanceof InetSocketAddress) {
InetSocketAddress temp = (InetSocketAddress) addr;

if (temp.isUnresolved()) {
return temp.getHostName() + ":" + temp.getPort();
}
}

return addr.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.ArcusReplNodeAddress;
import net.spy.memcached.MemcachedNode;
import net.spy.memcached.MemcachedReplicaGroup;
Expand Down Expand Up @@ -407,7 +408,7 @@ public final int getSelectionOps() {
}

public final String getNodeName() {
return name + " " + socketAddress;
return name + " " + AddrUtil.getSocketAddressString(socketAddress);
}

public final ByteBuffer getRbuf() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashMap;
import java.util.Map;

import net.spy.memcached.AddrUtil;
import net.spy.memcached.MemcachedNode;

/**
Expand Down Expand Up @@ -36,7 +37,7 @@ protected String getSocketAddressForNode(MemcachedNode node) {
// all other cases should be as fast as possible.
String result = socketAddresses.get(node);
if (result == null) {
result = String.valueOf(node.getSocketAddress());
result = AddrUtil.getSocketAddressString(node.getSocketAddress());
result = result.substring(result.indexOf('/') + 1);
socketAddresses.put(node, result);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/spy/memcached/MockMemcachedNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public int getSelectionOps() {

@Override
public String getNodeName() {
return socketAddress.toString();
return AddrUtil.getSocketAddressString(socketAddress);
}

public ByteBuffer getRbuf() {
Expand Down

0 comments on commit a462101

Please sign in to comment.