|
20 | 20 | import java.io.IOException; |
21 | 21 | import java.io.InputStream; |
22 | 22 | import java.io.OutputStream; |
23 | | -import java.lang.reflect.InvocationTargetException; |
24 | 23 | import java.net.InetAddress; |
25 | 24 | import java.net.Socket; |
26 | 25 | import java.net.SocketAddress; |
@@ -239,37 +238,19 @@ public void setPerformancePreferences(int connectionTime, |
239 | 238 | delegate.setPerformancePreferences(connectionTime, latency, bandwidth); |
240 | 239 | } |
241 | 240 |
|
242 | | - /** |
243 | | - * This method is only available in JDK9+ therefor reflection is used to call it. |
244 | | - */ |
245 | | - @SuppressWarnings({"PMD.MissingOverride", "unchecked"}) |
| 241 | + @Override |
246 | 242 | public Set<SocketOption<?>> supportedOptions() { |
247 | | - return invokeDelegateMethod("supportedOptions", new Class<?>[]{}); |
| 243 | + return delegate.supportedOptions(); |
248 | 244 | } |
249 | 245 |
|
250 | | - /** |
251 | | - * This method is only available in JDK9+ therefor reflection is used to call it. |
252 | | - */ |
253 | | - @SuppressWarnings({"PMD.MissingOverride", "unchecked"}) |
| 246 | + @Override |
254 | 247 | public <T> T getOption(SocketOption<T> name) throws IOException { |
255 | | - return invokeDelegateMethod("getOption", new Class<?>[]{SocketOption.class}, name); |
| 248 | + return delegate.getOption(name); |
256 | 249 | } |
257 | 250 |
|
258 | 251 |
|
259 | | - /** |
260 | | - * This method is only available in JDK9+ therefor reflection is used to call it. |
261 | | - */ |
262 | | - @SuppressWarnings("PMD.MissingOverride") |
| 252 | + @Override |
263 | 253 | public <T> Socket setOption(SocketOption<T> name, T value) throws IOException { |
264 | | - return invokeDelegateMethod("setOption", new Class<?>[]{SocketOption.class, Object.class}, name, value); |
265 | | - } |
266 | | - |
267 | | - @SuppressWarnings("unchecked") |
268 | | - private <T> T invokeDelegateMethod(String methodName, Class<?>[] parameterTypes, Object... args) { |
269 | | - try { |
270 | | - return (T) delegate.getClass().getMethod(methodName, parameterTypes).invoke(delegate, args); |
271 | | - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
272 | | - throw new UnsupportedOperationException("Socket option not supported", e); |
273 | | - } |
| 254 | + return delegate.setOption(name, value); |
274 | 255 | } |
275 | 256 | } |
0 commit comments