WriteTimeoutSocket::getFileDescriptor$ support for Conscrypt

https://github.com/eclipse-ee4j/mail/pull/507
pull/194/head
M66B 4 years ago
parent 61604e4408
commit dc6747a619

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at * terms of the Eclipse Public License v. 2.0, which is available at
@ -322,12 +322,20 @@ public class WriteTimeoutSocket extends Socket {
* @return the FileDescriptor object * @return the FileDescriptor object
*/ */
public FileDescriptor getFileDescriptor$() { public FileDescriptor getFileDescriptor$() {
try { //The loop handles issues with non-public classes between
Method m = Socket.class.getDeclaredMethod("getFileDescriptor$"); //java.net.Socket and the actual socket type held in this object.
return (FileDescriptor)m.invoke(socket); //Must inspect java.net.Socket to ensure compatiblity with old behavior.
} catch (Exception ex) { for (Class<?> k = socket.getClass(); k != Object.class; k = k.getSuperclass()) {
return null; try {
} Method m = k.getDeclaredMethod("getFileDescriptor$");
if (FileDescriptor.class.isAssignableFrom(m.getReturnType())) {
//Skip setAccessible so non-public methods fail to invoke.
return (FileDescriptor) m.invoke(socket);
}
} catch (Exception ignore) {
}
}
return null;
} }
} }

Loading…
Cancel
Save