mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8375480: Remove usage of AppContext from javax/swing/text
Reviewed-by: serb, psadhukhan
This commit is contained in:
parent
e88edd0bc6
commit
e617ccd529
@ -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,23 +1094,17 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
|
||||
return getKeymapTable().get(nm);
|
||||
}
|
||||
|
||||
private static HashMap<String,Keymap> getKeymapTable() {
|
||||
synchronized (KEYMAP_TABLE) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
@SuppressWarnings("unchecked")
|
||||
HashMap<String,Keymap> keymapTable =
|
||||
(HashMap<String,Keymap>)appContext.get(KEYMAP_TABLE);
|
||||
private static HashMap<String,Keymap> keymapTable;
|
||||
|
||||
private static synchronized HashMap<String,Keymap> getKeymapTable() {
|
||||
if (keymapTable == null) {
|
||||
keymapTable = new HashMap<String,Keymap>(17);
|
||||
appContext.put(KEYMAP_TABLE, keymapTable);
|
||||
//initialize default keymap
|
||||
Keymap binding = addKeymap(DEFAULT_KEYMAP, null);
|
||||
binding.setDefaultAction(new
|
||||
DefaultEditorKit.DefaultKeyTypedAction());
|
||||
binding.setDefaultAction(new DefaultEditorKit.DefaultKeyTypedAction());
|
||||
}
|
||||
return keymapTable;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binding record for creating key bindings.
|
||||
@ -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
|
||||
* <code>JTextComponent</code> 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) {
|
||||
|
||||
@ -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<Runnable> tasks;
|
||||
private Thread worker;
|
||||
|
||||
private static LayoutQueue defaultQueue;
|
||||
|
||||
/**
|
||||
* Construct a layout queue.
|
||||
*/
|
||||
@ -53,16 +52,11 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default layout queue.
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<String, DTD> getDtdHash() {
|
||||
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;
|
||||
}
|
||||
private static final Hashtable<String, DTD> DTD_MAP = new Hashtable<String, DTD>();
|
||||
|
||||
/**
|
||||
* Recreates a DTD from an archived format.
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user