MCPcopy Create free account
hub / github.com/M66B/FairEmail / findSocketChannel

Method findSocketChannel

app/src/main/java/com/sun/mail/iap/Protocol.java:564–604  ·  view source on GitHub ↗

Android is broken and SSL wrapped sockets don't delegate the getChannel method to the wrapped Socket. @param socket a non null socket @return the SocketChannel or null if not found

(Socket socket)

Source from the content-addressed store, hash-verified

562 * @return the SocketChannel or null if not found
563 */
564 private static SocketChannel findSocketChannel(Socket socket) {
565 //Search class hierarchy for field name socket regardless of modifier.
566 for (Class<?> k = socket.getClass(); k != Object.class; k = k.getSuperclass()) {
567 try {
568 Field f = k.getDeclaredField("socket");
569 f.setAccessible(true);
570 Socket s = (Socket) f.get(socket);
571 SocketChannel ret = s.getChannel();
572 if (ret != null) {
573 return ret;
574 }
575 } catch (Exception ignore) {
576 //ignore anything that might go wrong
577 }
578 }
579
580 //Search class hierarchy for fields that can hold a Socket
581 //or subclass regardless of modifier. Fields declared as super types of Socket
582 //will be ignored.
583 for (Class<?> k = socket.getClass(); k != Object.class; k = k.getSuperclass()) {
584 try {
585 for (Field f : k.getDeclaredFields()) {
586 if (Socket.class.isAssignableFrom(f.getType())) {
587 try {
588 f.setAccessible(true);
589 Socket s = (Socket) f.get(socket);
590 SocketChannel ret = s.getChannel();
591 if (ret != null) {
592 return ret;
593 }
594 } catch (Exception ignore) {
595 //ignore anything that might go wrong
596 }
597 }
598 }
599 } catch (Exception ignore) {
600 //ignore anything that might go wrong
601 }
602 }
603 return null;
604 }
605
606 /**
607 * Return the local SocketAddress (host and port) for this

Callers 1

getChannelMethod · 0.95

Calls 3

getMethod · 0.45
getChannelMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected