Skip to content

Commit a7031e1

Browse files
committed
Fix string parsing and TestHelper
1 parent aae0081 commit a7031e1

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

src/main/java/com/timgroup/statsd/UnixStreamClientChannel.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.ByteBuffer;
1010
import java.nio.ByteOrder;
1111
import java.nio.channels.SocketChannel;
12+
import java.lang.reflect.Method;
1213

1314
/**
1415
* A ClientChannel for Unix domain sockets.
@@ -105,16 +106,7 @@ private void connect() throws IOException {
105106
}
106107

107108
private void connectJdkSocket(long deadline) throws IOException {
108-
String socketPath;
109-
if (address instanceof UnixSocketAddress) {
110-
UnixSocketAddress unixAddr = (UnixSocketAddress) address;
111-
socketPath = unixAddr.path();
112-
} else {
113-
socketPath = address.toString();
114-
if (socketPath.startsWith("file://") || socketPath.startsWith("unix://")) {
115-
socketPath = socketPath.substring(7);
116-
}
117-
}
109+
String socketPath = address.toString();
118110

119111
try {
120112
// Use reflection to avoid compile-time dependency on Java 16+ classes
@@ -128,7 +120,8 @@ private void connectJdkSocket(long deadline) throws IOException {
128120

129121
try {
130122
delegate.configureBlocking(false);
131-
if (!delegate.connect((SocketAddress) udsAddress)) {
123+
// Use reflection to call the UDS specific connect method
124+
if (!delegate.connect(udsAddress)) {
132125
if (connectionTimeout > 0 && System.nanoTime() > deadline) {
133126
throw new IOException("Connection timed out");
134127
}

src/test/java/com/timgroup/statsd/TestHelpers.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@ static boolean isJnrAvailable() {
2020
}
2121
}
2222

23-
static boolean isJdkUdsAvailable() {
24-
try {
25-
Class.forName("java.nio.channels.DatagramChannel");
26-
return true;
27-
} catch (ClassNotFoundException e) {
28-
return false;
29-
}
30-
}
31-
3223
static boolean isUdsAvailable() {
33-
return (isLinux() || isMac()) && (isJdkUdsAvailable() || isJnrAvailable());
24+
return (isLinux() || isMac()) && isJnrAvailable();
3425
}
3526
}

0 commit comments

Comments
 (0)