On 14/03/18 14:39, Daniel Fuchs wrote:
Hi Chris,

key.interestOps() might throw CancelledKeyException in
which case you may trade an AssertionError for a
CancelledKeyException when building the assertion
message.

Maybe some of the other methods you call on key need
to be checked as well.

Good catch Daniel. Updated code:

--- a/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java
+++ b/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java
@@ -280,6 +280,16 @@
         }
     }

+    // assertion diagnostic information
+    private static String opsFromKey(SelectionKey key) {
+        try {
+            return String.format("interestOps:%d, readyOps:%d",
+                                 key.interestOps(), key.readyOps());
+        } catch (CancellationException cce) {
+            return "key has been cancelled";
+        }
+    }
+
     /* main server listener task */

     class Dispatcher implements Runnable {
@@ -408,7 +418,9 @@
                                     }
                                     handle (chan, conn);
                                 } else {
-                                    assert false;
+ assert false : String.format("Unexpected non-readable key," + + " where key's channel:%s, isValid:%b, %s", + key.channel(), key.isValid(), opsFromKey(key));
                                 }
                             } catch (CancelledKeyException e) {
                                 handleException(key, null);


-Chris.

Reply via email to