From e617ccd529657440eaf20ed68794fea6f6c07fee Mon Sep 17 00:00:00 2001 From: Phil Race Date: Fri, 23 Jan 2026 19:12:54 +0000 Subject: [PATCH] 8375480: Remove usage of AppContext from javax/swing/text Reviewed-by: serb, psadhukhan --- .../javax/swing/text/JTextComponent.java | 45 ++---- .../classes/javax/swing/text/LayoutQueue.java | 22 +-- .../javax/swing/text/html/HTMLEditorKit.java | 14 +- .../javax/swing/text/html/parser/DTD.java | 28 +--- .../javax/swing/text/html/parser/Element.java | 12 +- .../text/html/parser/ParserDelegator.java | 14 +- .../swing/Security/6938813/bug6938813.java | 128 ------------------ .../swing/text/LayoutQueue/Test6588003.java | 60 -------- .../swing/text/html/parser/Test8017492.java | 94 ------------- 9 files changed, 36 insertions(+), 381 deletions(-) delete mode 100644 test/jdk/javax/swing/Security/6938813/bug6938813.java delete mode 100644 test/jdk/javax/swing/text/LayoutQueue/Test6588003.java delete mode 100644 test/jdk/javax/swing/text/html/parser/Test8017492.java diff --git a/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java b/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java index 03e04d1c1a7..59cee1e12ee 100644 --- a/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java +++ b/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -62,9 +62,6 @@ import javax.accessibility.*; import javax.print.attribute.*; -import sun.awt.AppContext; - - import sun.swing.PrintingStatus; import sun.swing.SwingUtilities2; import sun.swing.text.TextComponentPrintable; @@ -1097,22 +1094,16 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A return getKeymapTable().get(nm); } - private static HashMap getKeymapTable() { - synchronized (KEYMAP_TABLE) { - AppContext appContext = AppContext.getAppContext(); - @SuppressWarnings("unchecked") - HashMap keymapTable = - (HashMap)appContext.get(KEYMAP_TABLE); - if (keymapTable == null) { - keymapTable = new HashMap(17); - appContext.put(KEYMAP_TABLE, keymapTable); - //initialize default keymap - Keymap binding = addKeymap(DEFAULT_KEYMAP, null); - binding.setDefaultAction(new - DefaultEditorKit.DefaultKeyTypedAction()); - } - return keymapTable; + private static HashMap keymapTable; + + private static synchronized HashMap getKeymapTable() { + if (keymapTable == null) { + keymapTable = new HashMap(17); + //initialize default keymap + Keymap binding = addKeymap(DEFAULT_KEYMAP, null); + binding.setDefaultAction(new DefaultEditorKit.DefaultKeyTypedAction()); } + return keymapTable; } /** @@ -1653,7 +1644,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A public void removeNotify() { super.removeNotify(); if (getFocusedComponent() == this) { - AppContext.getAppContext().remove(FOCUSED_COMPONENT); + focusedComponent = null; } } @@ -4084,13 +4075,14 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A } } + private static JTextComponent focusedComponent; + /** * Returns the JTextComponent that most recently had focus. The returned * value may currently have focus. */ static final JTextComponent getFocusedComponent() { - return (JTextComponent)AppContext.getAppContext(). - get(FOCUSED_COMPONENT); + return focusedComponent; } @SuppressWarnings("deprecation") @@ -4105,9 +4097,6 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A return modifiers; } - private static final Object KEYMAP_TABLE = - new StringBuilder("JTextComponent_KeymapTable"); - // // member variables used for on-the-spot input method // editing style support @@ -4438,9 +4427,6 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A } } - private static final Object FOCUSED_COMPONENT = - new StringBuilder("JTextComponent_FocusedComponent"); - /** * The default keymap that will be shared by all * JTextComponent instances unless they @@ -4493,8 +4479,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A // --- FocusListener methods ----------------------------------- public void focusGained(FocusEvent fe) { - AppContext.getAppContext().put(FOCUSED_COMPONENT, - fe.getSource()); + focusedComponent = (JTextComponent)fe.getSource(); } public void focusLost(FocusEvent fe) { diff --git a/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java b/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java index 6801a84da5b..1a4e7315eb4 100644 --- a/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java +++ b/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -25,7 +25,6 @@ package javax.swing.text; import java.util.Vector; -import sun.awt.AppContext; /** * A queue of text layout tasks. @@ -36,11 +35,11 @@ import sun.awt.AppContext; */ public class LayoutQueue { - private static final Object DEFAULT_QUEUE = new Object(); - private Vector tasks; private Thread worker; + private static LayoutQueue defaultQueue; + /** * Construct a layout queue. */ @@ -53,15 +52,10 @@ public class LayoutQueue { * @return the default layout queue */ public static LayoutQueue getDefaultQueue() { - AppContext ac = AppContext.getAppContext(); - synchronized (DEFAULT_QUEUE) { - LayoutQueue defaultQueue = (LayoutQueue) ac.get(DEFAULT_QUEUE); - if (defaultQueue == null) { - defaultQueue = new LayoutQueue(); - ac.put(DEFAULT_QUEUE, defaultQueue); - } - return defaultQueue; + if (defaultQueue == null) { + defaultQueue = new LayoutQueue(); } + return defaultQueue; } /** @@ -70,9 +64,7 @@ public class LayoutQueue { * @param q the new queue. */ public static void setDefaultQueue(LayoutQueue q) { - synchronized (DEFAULT_QUEUE) { - AppContext.getAppContext().put(DEFAULT_QUEUE, q); - } + defaultQueue = q; } /** diff --git a/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java b/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java index 53ceea32668..b5b75e1067b 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -92,7 +92,6 @@ import javax.swing.text.ViewFactory; import javax.swing.text.html.parser.ParserDelegator; import sun.swing.SwingAccessor; -import sun.awt.AppContext; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -432,11 +431,7 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible { * @param s a StyleSheet */ public void setStyleSheet(StyleSheet s) { - if (s == null) { - AppContext.getAppContext().remove(DEFAULT_STYLES_KEY); - } else { - AppContext.getAppContext().put(DEFAULT_STYLES_KEY, s); - } + defaultStyles = s; } /** @@ -448,12 +443,8 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible { * @return the StyleSheet */ public StyleSheet getStyleSheet() { - AppContext appContext = AppContext.getAppContext(); - StyleSheet defaultStyles = (StyleSheet) appContext.get(DEFAULT_STYLES_KEY); - if (defaultStyles == null) { defaultStyles = new StyleSheet(); - appContext.put(DEFAULT_STYLES_KEY, defaultStyles); try (InputStream is = HTMLEditorKit.getResourceAsStream(DEFAULT_CSS); InputStreamReader isr = new InputStreamReader(is, ISO_8859_1); Reader r = new BufferedReader(isr)) @@ -692,6 +683,7 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible { private static final ViewFactory defaultFactory = new HTMLFactory(); MutableAttributeSet input; + private static StyleSheet defaultStyles = null; private static final Object DEFAULT_STYLES_KEY = new Object(); private LinkController linkHandler = new LinkController(); private static Parser defaultParser = null; diff --git a/src/java.desktop/share/classes/javax/swing/text/html/parser/DTD.java b/src/java.desktop/share/classes/javax/swing/text/html/parser/DTD.java index e9999c679eb..d3a4fa76306 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/parser/DTD.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/parser/DTD.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -25,8 +25,6 @@ package javax.swing.text.html.parser; -import sun.awt.AppContext; - import java.io.PrintStream; import java.io.File; import java.io.FileInputStream; @@ -403,11 +401,6 @@ class DTD implements DTDConstants { return name; } - /** - * The hashtable key of DTDs in AppContext. - */ - private static final Object DTD_HASH_KEY = new Object(); - /** * Put a name and appropriate DTD to hashtable. * @@ -415,7 +408,7 @@ class DTD implements DTDConstants { * @param dtd the DTD */ public static void putDTDHash(String name, DTD dtd) { - getDtdHash().put(name, dtd); + DTD_MAP.put(name, dtd); } /** @@ -430,27 +423,14 @@ class DTD implements DTDConstants { */ public static DTD getDTD(String name) throws IOException { name = name.toLowerCase(); - DTD dtd = getDtdHash().get(name); + DTD dtd = DTD_MAP.get(name); if (dtd == null) dtd = new DTD(name); return dtd; } - private static Hashtable getDtdHash() { - AppContext appContext = AppContext.getAppContext(); - - @SuppressWarnings("unchecked") - Hashtable result = (Hashtable) appContext.get(DTD_HASH_KEY); - - if (result == null) { - result = new Hashtable(); - - appContext.put(DTD_HASH_KEY, result); - } - - return result; - } + private static final Hashtable DTD_MAP = new Hashtable(); /** * Recreates a DTD from an archived format. diff --git a/src/java.desktop/share/classes/javax/swing/text/html/parser/Element.java b/src/java.desktop/share/classes/javax/swing/text/html/parser/Element.java index cf8ea622c9b..8dd00373636 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/parser/Element.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/parser/Element.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -28,7 +28,6 @@ package javax.swing.text.html.parser; import java.io.Serializable; import java.util.BitSet; import java.util.Map; -import sun.awt.AppContext; /** * An element as described in a DTD using the ELEMENT construct. @@ -107,17 +106,14 @@ public final class Element implements DTDConstants, Serializable { this.name = name; this.index = index; if (index > getMaxIndex()) { - AppContext.getAppContext().put(MAX_INDEX_KEY, index); + maxIndex = index; } } - private static final Object MAX_INDEX_KEY = new Object(); + private static int maxIndex = 0; static int getMaxIndex() { - Integer value = (Integer) AppContext.getAppContext().get(MAX_INDEX_KEY); - return (value != null) - ? value.intValue() - : 0; + return maxIndex; } /** diff --git a/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java b/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java index 2d541abc06f..6971f313558 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -24,8 +24,6 @@ */ package javax.swing.text.html.parser; -import sun.awt.AppContext; - import javax.swing.text.html.HTMLEditorKit; import java.io.BufferedInputStream; import java.io.IOException; @@ -52,7 +50,8 @@ import java.io.Serializable; */ @SuppressWarnings("serial") // Same-version serialization only public class ParserDelegator extends HTMLEditorKit.Parser implements Serializable { - private static final Object DTD_KEY = new Object(); + + private static DTD dtd = null; /** * Sets the default DTD. @@ -62,10 +61,6 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl } private static synchronized DTD getDefaultDTD() { - AppContext appContext = AppContext.getAppContext(); - - DTD dtd = (DTD) appContext.get(DTD_KEY); - if (dtd == null) { DTD _dtd = null; // (PENDING) Hate having to hard code! @@ -77,10 +72,7 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl System.out.println("Throw an exception: could not get default dtd: " + nm); } dtd = createDTD(_dtd, nm); - - appContext.put(DTD_KEY, dtd); } - return dtd; } diff --git a/test/jdk/javax/swing/Security/6938813/bug6938813.java b/test/jdk/javax/swing/Security/6938813/bug6938813.java deleted file mode 100644 index 8f5e3fc3505..00000000000 --- a/test/jdk/javax/swing/Security/6938813/bug6938813.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2010, 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 6938813 - * @summary Swing mutable statics - * @author Pavel Porvatov - * @modules java.desktop/javax.swing.text.html.parser:open - * @modules java.desktop/sun.awt - */ - -import sun.awt.AppContext; -import sun.awt.SunToolkit; - -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.StyleSheet; -import javax.swing.text.html.parser.DTD; -import javax.swing.text.html.parser.ParserDelegator; -import java.lang.reflect.Field; - -public class bug6938813 { - public static final String DTD_KEY = "dtd_key"; - - private static volatile StyleSheet styleSheet; - - public static void main(String[] args) throws Exception { - // Run validation and init values for this AppContext - validate(); - - Thread thread = new ThreadInAnotherAppContext(); - - thread.start(); - thread.join(); - } - - private static void validate() throws Exception { - AppContext appContext = AppContext.getAppContext(); - - assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts"); - - // Spoil hash value - DTD invalidDtd = DTD.getDTD("invalid DTD"); - - DTD.putDTDHash(DTD_KEY, invalidDtd); - - assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()"); - - Object dtdKey = getParserDelegator_DTD_KEY(); - - assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts"); - - // Init default DTD - new ParserDelegator(); - - Object dtdValue = appContext.get(dtdKey); - - assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized"); - - // Try reinit default DTD - new ParserDelegator(); - - assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate"); - - HTMLEditorKit htmlEditorKit = new HTMLEditorKit(); - - if (styleSheet == null) { - // First AppContext - styleSheet = htmlEditorKit.getStyleSheet(); - - assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null"); - assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()"); - } else { - assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts"); - } - } - - private static void assertTrue(boolean b, String msg) { - if (!b) { - throw new RuntimeException("Test failed: " + msg); - } - } - - private static Object getParserDelegator_DTD_KEY() throws Exception { - Field field = ParserDelegator.class.getDeclaredField("DTD_KEY"); - - field.setAccessible(true); - - return field.get(null); - } - - private static class ThreadInAnotherAppContext extends Thread { - public ThreadInAnotherAppContext() { - super(new ThreadGroup("6938813"), "ThreadInAnotherAppContext"); - } - - public void run() { - SunToolkit.createNewAppContext(); - - try { - validate(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } -} diff --git a/test/jdk/javax/swing/text/LayoutQueue/Test6588003.java b/test/jdk/javax/swing/text/LayoutQueue/Test6588003.java deleted file mode 100644 index 561ac594a47..00000000000 --- a/test/jdk/javax/swing/text/LayoutQueue/Test6588003.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2007, 2015, 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 - @bug 6588003 - @summary LayoutQueue should not share its DefaultQueue across AppContexts - @author Peter Zhelezniakov - @modules java.desktop/sun.awt - @run main Test6588003 -*/ - -import javax.swing.text.LayoutQueue; -import sun.awt.SunToolkit; - -public class Test6588003 implements Runnable { - private static final LayoutQueue DEFAULT = new LayoutQueue(); - - public static void main(String[] args) throws InterruptedException { - LayoutQueue.setDefaultQueue(DEFAULT); - - ThreadGroup group = new ThreadGroup("Test6588003"); - Thread thread = new Thread(group, new Test6588003()); - thread.start(); - thread.join(); - - if (LayoutQueue.getDefaultQueue() != DEFAULT) { - throw new RuntimeException("Sharing detected"); - } - } - - public void run() { - SunToolkit.createNewAppContext(); - - if (LayoutQueue.getDefaultQueue() == DEFAULT) { - throw new RuntimeException("Sharing detected"); - } - - LayoutQueue.setDefaultQueue(new LayoutQueue()); - } -} diff --git a/test/jdk/javax/swing/text/html/parser/Test8017492.java b/test/jdk/javax/swing/text/html/parser/Test8017492.java deleted file mode 100644 index dbc1e125cf7..00000000000 --- a/test/jdk/javax/swing/text/html/parser/Test8017492.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2013, 2020, 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. - */ - -import java.util.Vector; -import javax.swing.text.html.HTML; -import javax.swing.text.html.HTMLDocument; -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.parser.DTD; -import javax.swing.text.html.parser.Element; -import sun.awt.SunToolkit; - -/* - * @test - * @bug 8017492 - * @modules java.desktop/sun.awt - * @run main/othervm Test8017492 - * @summary Tests for OutOfMemoryError/NegativeArraySizeException - * @author Sergey Malenkov - */ - -public class Test8017492 { - public static void main(String[] args) throws Exception { - Runnable task = new Runnable() { - @Override - public void run() { - try { - SunToolkit.createNewAppContext(); - DTD dtd = DTD.getDTD("dtd"); - dtd.elements = new Vector() { - @Override - public synchronized int size() { - return Integer.MAX_VALUE; - } - }; - dtd.getElement("element"); - } - catch (Exception exception) { - throw new Error("unexpected", exception); - } - } - }; - // run task with different AppContext - Thread thread = new Thread(new ThreadGroup("$$$"), task); - thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread thread, Throwable throwable) { - throwable.printStackTrace(); - throw new RuntimeException(throwable); - } - }); - thread.start(); - thread.join(); - // add error handling - SunToolkit.createNewAppContext(); - HTMLDocument document = new HTMLDocument() { - @Override - public HTMLEditorKit.ParserCallback getReader(int pos) { - return getReader(pos, 0, 0, null); - } - - @Override - public HTMLEditorKit.ParserCallback getReader(int pos, int popDepth, int pushDepth, HTML.Tag insertTag) { - return new HTMLDocument.HTMLReader(pos, popDepth, pushDepth, insertTag) { - @Override - public void handleError(String error, int pos) { - throw new Error(error); - } - }; - } - }; - // run parser - new HTMLEditorKit().insertHTML(document, 0, "text", 0, 0, null); - } -}