From a4daabbbfa3184b0dcce1db73502f69f601978f0 Mon Sep 17 00:00:00 2001 From: Damon Nguyen Date: Tue, 10 Mar 2026 22:13:37 +0000 Subject: [PATCH] 8237220: [macOS] AWT text test CorrectTextComponentSelectionTest.html sometimes fails Reviewed-by: aivanov, prr, dmarkov --- test/jdk/ProblemList.txt | 1 - .../CorrectTextComponentSelectionTest.java | 39 ++++++------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index de1a0a49d1e..38ffe2ae963 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -758,7 +758,6 @@ java/awt/FileDialog/DefaultFocusOwner/DefaultFocusOwner.java 7187728 macosx-all, java/awt/FileDialog/DoubleActionESC.java 8356981 linux-all java/awt/print/PageFormat/Orient.java 8016055 macosx-all java/awt/TextArea/TextAreaCursorTest/HoveringAndDraggingTest.java 8024986 macosx-all,linux-all -java/awt/TextComponent/CorrectTextComponentSelectionTest.java 8237220 macosx-all java/awt/TextComponent/SelectionAndCaretColor.java 7017622 linux-all java/awt/event/MouseEvent/SpuriousExitEnter/SpuriousExitEnter.java 8254841 macosx-all java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java 8258103 linux-all diff --git a/test/jdk/java/awt/TextComponent/CorrectTextComponentSelectionTest.java b/test/jdk/java/awt/TextComponent/CorrectTextComponentSelectionTest.java index 9d3e6d85637..b2352dc04ff 100644 --- a/test/jdk/java/awt/TextComponent/CorrectTextComponentSelectionTest.java +++ b/test/jdk/java/awt/TextComponent/CorrectTextComponentSelectionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2026, 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 @@ -23,9 +23,9 @@ /* * @test + * @key headful * @bug 5100806 * @summary TextArea.select(0,0) does not de-select the selected text properly - * @key headful * @run main CorrectTextComponentSelectionTest */ @@ -38,7 +38,6 @@ import java.awt.Robot; import java.awt.TextArea; import java.awt.TextComponent; import java.awt.TextField; -import java.lang.reflect.InvocationTargetException; public class CorrectTextComponentSelectionTest { static TextField tf = new TextField("TextField"); @@ -46,14 +45,11 @@ public class CorrectTextComponentSelectionTest { static Robot r; static Frame frame; static volatile Color color_center; - static volatile Point loc; public static void main(String[] args) throws Exception { try { r = new Robot(); - EventQueue.invokeAndWait(() -> { - initialize(); - }); + EventQueue.invokeAndWait(() -> initialize()); r.waitForIdle(); r.delay(1000); @@ -75,24 +71,13 @@ public class CorrectTextComponentSelectionTest { // We should place to the text components the long strings in order to // cover the components by the selection completely - String sf = ""; - for (int i = 0; i < 50; i++) { - sf = sf + " "; - } - tf.setText(sf); + tf.setText(" ".repeat(50)); // We check the color of the text component in order to find out the // bug reproducible situation tf.setForeground(Color.WHITE); tf.setBackground(Color.WHITE); - String sa = ""; - for (int i = 0; i < 50; i++) { - for (int j = 0; j < 50; j++) { - sa = sa + " "; - } - sa = sa + "\n"; - } - ta.setText(sa); + ta.setText((" ".repeat(50) + "\n").repeat(50)); ta.setForeground(Color.WHITE); ta.setBackground(Color.WHITE); @@ -111,26 +96,24 @@ public class CorrectTextComponentSelectionTest { r.waitForIdle(); r.delay(100); + EventQueue.invokeAndWait(() -> { tc.requestFocus(); tc.selectAll(); tc.select(0, 0); }); - r.waitForIdle(); - r.delay(100); - EventQueue.invokeAndWait(() -> { - loc = tc.getLocationOnScreen(); - }); r.waitForIdle(); r.delay(100); EventQueue.invokeAndWait(() -> { - color_center = r.getPixelColor(loc.x + tc.getWidth() / 2, loc.y + tc.getHeight() / 2); + Point p = tc.getLocationOnScreen(); + p.translate(tc.getWidth() / 2, tc.getHeight() / 2); + color_center = r.getPixelColor(p.x, p.y); }); - System.out.println("Color of the text component (CENTER) =" + color_center); - System.out.println("White color=" + Color.WHITE); + System.out.println("Color of the text component (CENTER) = " + color_center); + System.out.println("White color = " + Color.WHITE); if (color_center.getRGB() != Color.WHITE.getRGB()) { throw new RuntimeException("Test Failed");