8375480: Remove usage of AppContext from javax/swing/text

Reviewed-by: serb, psadhukhan
This commit is contained in:
Phil Race 2026-01-23 19:12:54 +00:00
parent e88edd0bc6
commit e617ccd529
9 changed files with 36 additions and 381 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 javax.print.attribute.*;
import sun.awt.AppContext;
import sun.swing.PrintingStatus; import sun.swing.PrintingStatus;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
import sun.swing.text.TextComponentPrintable; import sun.swing.text.TextComponentPrintable;
@ -1097,22 +1094,16 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
return getKeymapTable().get(nm); return getKeymapTable().get(nm);
} }
private static HashMap<String,Keymap> getKeymapTable() { private static HashMap<String,Keymap> keymapTable;
synchronized (KEYMAP_TABLE) {
AppContext appContext = AppContext.getAppContext(); private static synchronized HashMap<String,Keymap> getKeymapTable() {
@SuppressWarnings("unchecked") if (keymapTable == null) {
HashMap<String,Keymap> keymapTable = keymapTable = new HashMap<String,Keymap>(17);
(HashMap<String,Keymap>)appContext.get(KEYMAP_TABLE); //initialize default keymap
if (keymapTable == null) { Keymap binding = addKeymap(DEFAULT_KEYMAP, null);
keymapTable = new HashMap<String,Keymap>(17); binding.setDefaultAction(new DefaultEditorKit.DefaultKeyTypedAction());
appContext.put(KEYMAP_TABLE, keymapTable);
//initialize default keymap
Keymap binding = addKeymap(DEFAULT_KEYMAP, null);
binding.setDefaultAction(new
DefaultEditorKit.DefaultKeyTypedAction());
}
return keymapTable;
} }
return keymapTable;
} }
/** /**
@ -1653,7 +1644,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
public void removeNotify() { public void removeNotify() {
super.removeNotify(); super.removeNotify();
if (getFocusedComponent() == this) { 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 * Returns the JTextComponent that most recently had focus. The returned
* value may currently have focus. * value may currently have focus.
*/ */
static final JTextComponent getFocusedComponent() { static final JTextComponent getFocusedComponent() {
return (JTextComponent)AppContext.getAppContext(). return focusedComponent;
get(FOCUSED_COMPONENT);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -4105,9 +4097,6 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
return modifiers; return modifiers;
} }
private static final Object KEYMAP_TABLE =
new StringBuilder("JTextComponent_KeymapTable");
// //
// member variables used for on-the-spot input method // member variables used for on-the-spot input method
// editing style support // 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 * The default keymap that will be shared by all
* <code>JTextComponent</code> instances unless they * <code>JTextComponent</code> instances unless they
@ -4493,8 +4479,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
// --- FocusListener methods ----------------------------------- // --- FocusListener methods -----------------------------------
public void focusGained(FocusEvent fe) { public void focusGained(FocusEvent fe) {
AppContext.getAppContext().put(FOCUSED_COMPONENT, focusedComponent = (JTextComponent)fe.getSource();
fe.getSource());
} }
public void focusLost(FocusEvent fe) { public void focusLost(FocusEvent fe) {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package javax.swing.text; package javax.swing.text;
import java.util.Vector; import java.util.Vector;
import sun.awt.AppContext;
/** /**
* A queue of text layout tasks. * A queue of text layout tasks.
@ -36,11 +35,11 @@ import sun.awt.AppContext;
*/ */
public class LayoutQueue { public class LayoutQueue {
private static final Object DEFAULT_QUEUE = new Object();
private Vector<Runnable> tasks; private Vector<Runnable> tasks;
private Thread worker; private Thread worker;
private static LayoutQueue defaultQueue;
/** /**
* Construct a layout queue. * Construct a layout queue.
*/ */
@ -53,15 +52,10 @@ public class LayoutQueue {
* @return the default layout queue * @return the default layout queue
*/ */
public static LayoutQueue getDefaultQueue() { public static LayoutQueue getDefaultQueue() {
AppContext ac = AppContext.getAppContext(); if (defaultQueue == null) {
synchronized (DEFAULT_QUEUE) { defaultQueue = new LayoutQueue();
LayoutQueue defaultQueue = (LayoutQueue) ac.get(DEFAULT_QUEUE);
if (defaultQueue == null) {
defaultQueue = new LayoutQueue();
ac.put(DEFAULT_QUEUE, defaultQueue);
}
return defaultQueue;
} }
return defaultQueue;
} }
/** /**
@ -70,9 +64,7 @@ public class LayoutQueue {
* @param q the new queue. * @param q the new queue.
*/ */
public static void setDefaultQueue(LayoutQueue q) { public static void setDefaultQueue(LayoutQueue q) {
synchronized (DEFAULT_QUEUE) { defaultQueue = q;
AppContext.getAppContext().put(DEFAULT_QUEUE, q);
}
} }
/** /**

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 javax.swing.text.html.parser.ParserDelegator;
import sun.swing.SwingAccessor; import sun.swing.SwingAccessor;
import sun.awt.AppContext;
import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.ISO_8859_1;
@ -432,11 +431,7 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
* @param s a StyleSheet * @param s a StyleSheet
*/ */
public void setStyleSheet(StyleSheet s) { public void setStyleSheet(StyleSheet s) {
if (s == null) { defaultStyles = s;
AppContext.getAppContext().remove(DEFAULT_STYLES_KEY);
} else {
AppContext.getAppContext().put(DEFAULT_STYLES_KEY, s);
}
} }
/** /**
@ -448,12 +443,8 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
* @return the StyleSheet * @return the StyleSheet
*/ */
public StyleSheet getStyleSheet() { public StyleSheet getStyleSheet() {
AppContext appContext = AppContext.getAppContext();
StyleSheet defaultStyles = (StyleSheet) appContext.get(DEFAULT_STYLES_KEY);
if (defaultStyles == null) { if (defaultStyles == null) {
defaultStyles = new StyleSheet(); defaultStyles = new StyleSheet();
appContext.put(DEFAULT_STYLES_KEY, defaultStyles);
try (InputStream is = HTMLEditorKit.getResourceAsStream(DEFAULT_CSS); try (InputStream is = HTMLEditorKit.getResourceAsStream(DEFAULT_CSS);
InputStreamReader isr = new InputStreamReader(is, ISO_8859_1); InputStreamReader isr = new InputStreamReader(is, ISO_8859_1);
Reader r = new BufferedReader(isr)) Reader r = new BufferedReader(isr))
@ -692,6 +683,7 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
private static final ViewFactory defaultFactory = new HTMLFactory(); private static final ViewFactory defaultFactory = new HTMLFactory();
MutableAttributeSet input; MutableAttributeSet input;
private static StyleSheet defaultStyles = null;
private static final Object DEFAULT_STYLES_KEY = new Object(); private static final Object DEFAULT_STYLES_KEY = new Object();
private LinkController linkHandler = new LinkController(); private LinkController linkHandler = new LinkController();
private static Parser defaultParser = null; private static Parser defaultParser = null;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,8 +25,6 @@
package javax.swing.text.html.parser; package javax.swing.text.html.parser;
import sun.awt.AppContext;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -403,11 +401,6 @@ class DTD implements DTDConstants {
return name; 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. * Put a name and appropriate DTD to hashtable.
* *
@ -415,7 +408,7 @@ class DTD implements DTDConstants {
* @param dtd the DTD * @param dtd the DTD
*/ */
public static void putDTDHash(String name, DTD 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 { public static DTD getDTD(String name) throws IOException {
name = name.toLowerCase(); name = name.toLowerCase();
DTD dtd = getDtdHash().get(name); DTD dtd = DTD_MAP.get(name);
if (dtd == null) if (dtd == null)
dtd = new DTD(name); dtd = new DTD(name);
return dtd; return dtd;
} }
private static Hashtable<String, DTD> getDtdHash() { private static final Hashtable<String, DTD> DTD_MAP = new Hashtable<String, DTD>();
AppContext appContext = AppContext.getAppContext();
@SuppressWarnings("unchecked")
Hashtable<String, DTD> result = (Hashtable<String, DTD>) appContext.get(DTD_HASH_KEY);
if (result == null) {
result = new Hashtable<String, DTD>();
appContext.put(DTD_HASH_KEY, result);
}
return result;
}
/** /**
* Recreates a DTD from an archived format. * Recreates a DTD from an archived format.

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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.io.Serializable;
import java.util.BitSet; import java.util.BitSet;
import java.util.Map; import java.util.Map;
import sun.awt.AppContext;
/** /**
* An element as described in a DTD using the ELEMENT construct. * 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.name = name;
this.index = index; this.index = index;
if (index > getMaxIndex()) { 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() { static int getMaxIndex() {
Integer value = (Integer) AppContext.getAppContext().get(MAX_INDEX_KEY); return maxIndex;
return (value != null)
? value.intValue()
: 0;
} }
/** /**

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,8 +24,6 @@
*/ */
package javax.swing.text.html.parser; package javax.swing.text.html.parser;
import sun.awt.AppContext;
import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.HTMLEditorKit;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
@ -52,7 +50,8 @@ import java.io.Serializable;
*/ */
@SuppressWarnings("serial") // Same-version serialization only @SuppressWarnings("serial") // Same-version serialization only
public class ParserDelegator extends HTMLEditorKit.Parser implements Serializable { 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. * Sets the default DTD.
@ -62,10 +61,6 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl
} }
private static synchronized DTD getDefaultDTD() { private static synchronized DTD getDefaultDTD() {
AppContext appContext = AppContext.getAppContext();
DTD dtd = (DTD) appContext.get(DTD_KEY);
if (dtd == null) { if (dtd == null) {
DTD _dtd = null; DTD _dtd = null;
// (PENDING) Hate having to hard code! // (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); System.out.println("Throw an exception: could not get default dtd: " + nm);
} }
dtd = createDTD(_dtd, nm); dtd = createDTD(_dtd, nm);
appContext.put(DTD_KEY, dtd);
} }
return dtd; return dtd;
} }

View File

@ -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);
}
}
}
}

View File

@ -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());
}
}

View File

@ -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<Element>() {
@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, "<html><body>text", 0, 0, null);
}
}