src/java.base/share/classes/java/nio/channels/spi/AbstractSelectableChannel.java
changeset 59146 455612b3161a
parent 49802 8ac08fa69f00
--- a/src/java.base/share/classes/java/nio/channels/spi/AbstractSelectableChannel.java	Wed Nov 20 09:12:07 2019 +0100
+++ b/src/java.base/share/classes/java/nio/channels/spi/AbstractSelectableChannel.java	Wed Nov 20 08:35:53 2019 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,8 @@
 import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
+import java.util.Arrays;
+import java.util.function.Consumer;
 
 
 /**
@@ -172,6 +174,20 @@
     }
 
     /**
+     * Invokes an action for each key.
+     *
+     * This method is invoked by DatagramChannelImpl::disconnect.
+     */
+    private void forEach(Consumer<SelectionKey> action) {
+        synchronized (keyLock) {
+            SelectionKey[] keys = this.keys;
+            if (keys != null) {
+                Arrays.stream(keys).filter(k -> k != null).forEach(action::accept);
+            }
+        }
+    }
+
+    /**
      * Registers this channel with the given selector, returning a selection key.
      *
      * <p>  This method first verifies that this channel is open and that the