From a95799d62fc0ec8e8fcdfd62813273c6896845ef Mon Sep 17 00:00:00 2001 From: Phil Race Date: Mon, 9 Mar 2026 19:32:47 +0000 Subject: [PATCH] 8379229: Remove AppContext from javax.swing.JComponent Reviewed-by: psadhukhan, serb --- .../share/classes/javax/swing/JComponent.java | 62 ++++------- .../awt/dnd/BadSerializationTest/badAction | Bin 3651 -> 3651 bytes .../java/awt/dnd/BadSerializationTest/good | Bin 3457 -> 3651 bytes .../awt/dnd/BadSerializationTest/noEvents | Bin 3160 -> 3160 bytes .../dnd/BadSerializationTest/nullComponent | Bin 3470 -> 3470 bytes .../dnd/BadSerializationTest/nullDragSource | Bin 3609 -> 3609 bytes .../awt/dnd/BadSerializationTest/nullOrigin | Bin 3605 -> 3605 bytes .../swing/JComponent/8043610/bug8043610.java | 102 ------------------ 8 files changed, 19 insertions(+), 145 deletions(-) delete mode 100644 test/jdk/javax/swing/JComponent/8043610/bug8043610.java diff --git a/src/java.desktop/share/classes/javax/swing/JComponent.java b/src/java.desktop/share/classes/javax/swing/JComponent.java index 6351522ab49..87d6a41c2b0 100644 --- a/src/java.desktop/share/classes/javax/swing/JComponent.java +++ b/src/java.desktop/share/classes/javax/swing/JComponent.java @@ -31,6 +31,7 @@ import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; +import java.awt.EventQueue; import java.awt.FocusTraversalPolicy; import java.awt.Font; import java.awt.FontMetrics; @@ -261,16 +262,6 @@ public abstract class JComponent extends Container implements Serializable, */ static boolean DEBUG_GRAPHICS_LOADED; - /** - * Key used to look up a value from the AppContext to determine the - * JComponent the InputVerifier is running for. That is, if - * AppContext.get(INPUT_VERIFIER_SOURCE_KEY) returns non-null, it - * indicates the EDT is calling into the InputVerifier from the - * returned component. - */ - private static final Object INPUT_VERIFIER_SOURCE_KEY = - new StringBuilder("InputVerifierSourceKey"); - /* The following fields support set methods for the corresponding * java.awt.Component properties. */ @@ -414,8 +405,7 @@ public abstract class JComponent extends Container implements Serializable, /** ActionMap. */ private ActionMap actionMap; - /** Key used to store the default locale in an AppContext **/ - private static final String defaultLocale = "JComponent.defaultLocale"; + private static volatile Locale defaultLocale; private static Component componentObtainingGraphicsFrom; private static Object componentObtainingGraphicsFromLock = new @@ -2841,12 +2831,12 @@ public abstract class JComponent extends Container implements Serializable, * @since 1.4 */ public static Locale getDefaultLocale() { - Locale l = (Locale) SwingUtilities.appContextGet(defaultLocale); - if( l == null ) { + Locale l = defaultLocale; + if (l == null) { //REMIND(bcb) choosing the default value is more complicated //than this. l = Locale.getDefault(); - JComponent.setDefaultLocale( l ); + JComponent.setDefaultLocale(l); } return l; } @@ -2865,8 +2855,8 @@ public abstract class JComponent extends Container implements Serializable, * @see #setLocale * @since 1.4 */ - public static void setDefaultLocale( Locale l ) { - SwingUtilities.appContextPut(defaultLocale, l); + public static void setDefaultLocale(Locale l) { + defaultLocale = l; } @@ -3507,7 +3497,7 @@ public abstract class JComponent extends Container implements Serializable, // This class is used by the KeyboardState class to provide a single - // instance that can be stored in the AppContext. + // instance. static final class IntVector { int[] array = null; int count = 0; @@ -3538,24 +3528,12 @@ public abstract class JComponent extends Container implements Serializable, } } + private static final IntVector intVector = new IntVector(); @SuppressWarnings("serial") static class KeyboardState implements Serializable { - private static final Object keyCodesKey = - JComponent.KeyboardState.class; - - // Get the array of key codes from the AppContext. - static IntVector getKeyCodeArray() { - IntVector iv = - (IntVector)SwingUtilities.appContextGet(keyCodesKey); - if (iv == null) { - iv = new IntVector(); - SwingUtilities.appContextPut(keyCodesKey, iv); - } - return iv; - } static void registerKeyPressed(int keyCode) { - IntVector kca = getKeyCodeArray(); + IntVector kca = intVector; int count = kca.size(); int i; for(i=0;isb692r8zYBi{;A-#hYyx*=3{i{WC{)59M1KI833h=3Yh=^ delta 29 lcmX>sb692r8zYDP+TDi)e`ihJ%*W`?$rKd2Ih^YaGXSW13a$VE diff --git a/test/jdk/java/awt/dnd/BadSerializationTest/good b/test/jdk/java/awt/dnd/BadSerializationTest/good index 523df353a1aad149c7110bb0c45d509c9a55d5cb..f5dd0e2cb5bd8cd009c2023c1b66bffdde19f74e 100644 GIT binary patch delta 378 zcmZpaJ}k3=jgdn$|5WhW!w1VY^D*YKdFUtS=jtUE6y&7p3u;K&q7(Ab`C90)YB-G2P*opI1_>;*wgFS(cg- z>KT+;oL^d$oC*?t*M04dMT=N3$iN~7d61nIdc~8CId;effQ{w_kp(3TygsGLnJI}1 z?nQ}tDXA5cE7%Qq;V$?OR5O{MvqdB{xP*bBgn=nF4s(?LUck&VT8rA|JD4x8P2r`6$0VHBl05;Zi5}&bvc|iqGT{#O#t^x=ErUEbA diff --git a/test/jdk/java/awt/dnd/BadSerializationTest/noEvents b/test/jdk/java/awt/dnd/BadSerializationTest/noEvents index a45ba168c71de59fcc1b27af7eee1cc081de77dc..fdf1125889fc3ab000cc035b2ccfcdcddd917c50 100644 GIT binary patch delta 29 lcmca1aYJGQ8zYBi{;A-#hYyx*=3{i{WC{)59L~ka1OTUW3C{ok delta 29 lcmca1aYJGQ8zYDP+TDi)e`ihJ%*W`?$rKd2Ih>1;2>_~N3FH6( diff --git a/test/jdk/java/awt/dnd/BadSerializationTest/nullComponent b/test/jdk/java/awt/dnd/BadSerializationTest/nullComponent index 63aee01cc2ce59e126e5d2cf3ad52040a7df9e2b..d5dfcada90cfec9e9a4758e4f7c527998929a453 100644 GIT binary patch delta 29 lcmeB^?vvhdnu$X*|5WhW!w1VYUuJUWWC{)5EW=a82mrIU3j_cF delta 29 lcmeB^?vvhdnu)`H?e0T@zq2N9zRcv#$rKd2S%#;G5dgNP3mE_a diff --git a/test/jdk/java/awt/dnd/BadSerializationTest/nullDragSource b/test/jdk/java/awt/dnd/BadSerializationTest/nullDragSource index a483f7106a8ad1779dfb54593277fbe2183fafea..efdfeb3ed20a4cff964f112ecb5507507efbaf77 100644 GIT binary patch delta 29 lcmbO!GgD>*8zYBi{;A-#hYyx*=3{i{WC{)59L{x!833FI3L5|b delta 29 lcmbO!GgD>*8zYDP+TDi)e`ihJ%*W`?$rKd2Ih^YdGXS3U3NQcw diff --git a/test/jdk/java/awt/dnd/BadSerializationTest/nullOrigin b/test/jdk/java/awt/dnd/BadSerializationTest/nullOrigin index 5af1996e74b38800dcfeb62184d0181e738fef40..17d9fd3a1a9f6a232a7c6a1b8fe56b9b1080c42c 100644 GIT binary patch delta 29 lcmbO#GgW2-8zYBi{;A-#hYyx*=3{i{WC{)59L}|m833Cf3J(AP delta 29 lcmbO#GgW2-8zYDP+TDi)e`ihJ%*W`?$rKd2Ih<=BGXS0r3M2pk diff --git a/test/jdk/javax/swing/JComponent/8043610/bug8043610.java b/test/jdk/javax/swing/JComponent/8043610/bug8043610.java deleted file mode 100644 index 7eb371d1a0e..00000000000 --- a/test/jdk/javax/swing/JComponent/8043610/bug8043610.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2014, 2017, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -/** - * @test - * @key headful - * @bug 8043610 - * @summary Tests that JComponent invalidate, revalidate and repaint methods could - * be called from any thread - * @author Petr Pchelko - * @modules java.desktop/sun.awt - */ - -import sun.awt.SunToolkit; - -import javax.swing.*; -import java.awt.*; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -public class bug8043610 { - private static volatile JFrame frame; - private static volatile JComponent component; - - public static void main(String[] args) throws Exception { - ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group"); - ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG"); - try { - Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext); - stubThread.start(); - stubThread.join(); - - CountDownLatch startSwingLatch = new CountDownLatch(1); - new Thread(swingTG, () -> { - SunToolkit.createNewAppContext(); - SwingUtilities.invokeLater(() -> { - frame = new JFrame(); - component = new JLabel("Test Text"); - frame.add(component); - frame.setBounds(100, 100, 100, 100); - frame.setVisible(true); - startSwingLatch.countDown(); - }); - }).start(); - startSwingLatch.await(); - - AtomicReference caughtException = new AtomicReference<>(); - Thread checkThread = new Thread(getRootThreadGroup(), () -> { - try { - component.invalidate(); - component.revalidate(); - component.repaint(new Rectangle(0, 0, 0, 0)); - } catch (Exception e) { - caughtException.set(e); - } - }); - checkThread.start(); - checkThread.join(); - - if (caughtException.get() != null) { - throw new RuntimeException("Failed. Caught exception!", caughtException.get()); - } - } finally { - new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> { - if (frame != null) { - frame.dispose(); - } - })).start(); - } - } - - private static ThreadGroup getRootThreadGroup() { - ThreadGroup currentTG = Thread.currentThread().getThreadGroup(); - ThreadGroup parentTG = currentTG.getParent(); - while (parentTG != null) { - currentTG = parentTG; - parentTG = currentTG.getParent(); - } - return currentTG; - } -}