diff --git a/modules/graphics/src/main/java/javafx/stage/Window.java b/modules/graphics/src/main/java/javafx/stage/Window.java --- a/modules/graphics/src/main/java/javafx/stage/Window.java +++ b/modules/graphics/src/main/java/javafx/stage/Window.java @@ -28,8 +28,10 @@ import java.security.AllPermission; import java.security.AccessControlContext; import java.security.AccessController; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import javafx.beans.property.DoubleProperty; import javafx.beans.property.DoublePropertyBase; @@ -134,20 +136,25 @@ } /** - * Return all Windows + * Returns a list containing a reference to the currently existing JavaFX windows. The list, whilst mutable, is + * simply a reflection of the state at that moment in time - modifying the list will have no impact at all. * - * @return Iterator of all Windows - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version + *

It is strong encouraged that developers do not retain a reference to this list outside of their immediate + * use case (i.e. within the relevant method), as doing so can lead to memory leaks.

+ * + * @return A list containing all windows currently showing. + * @since 9 */ - @Deprecated - public static Iterator impl_getWindows() { + public static List getWindows() { final SecurityManager securityManager = System.getSecurityManager(); if (securityManager != null) { securityManager.checkPermission(new AllPermission()); } - return (Iterator) windowQueue.iterator(); + Iterator it = (Iterator) windowQueue.iterator(); + List windows = new ArrayList<>(); + it.forEachRemaining(windows::add); + return windows; } final AccessControlContext acc = AccessController.getContext();