author | malenkov |
Mon, 15 Jul 2013 17:33:44 +0400 | |
changeset 18764 | 12a1993f109b |
child 31448 | 1066345d2a8a |
permissions | -rw-r--r-- |
18764
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
1 |
/* |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
4 |
* |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
8 |
* |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
13 |
* accompanied this code). |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
14 |
* |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
18 |
* |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
21 |
* questions. |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
22 |
*/ |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
23 |
|
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
24 |
import java.util.Vector; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
25 |
import javax.swing.text.html.HTML; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
26 |
import javax.swing.text.html.HTMLDocument; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
27 |
import javax.swing.text.html.HTMLEditorKit; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
28 |
import javax.swing.text.html.parser.DTD; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
29 |
import javax.swing.text.html.parser.Element; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
30 |
import sun.awt.SunToolkit; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
31 |
|
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
32 |
/* |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
33 |
* @test |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
34 |
* @bug 8017492 |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
35 |
* @run main/othervm Test8017492 |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
36 |
* @summary Tests for OutOfMemoryError/NegativeArraySizeException |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
37 |
* @author Sergey Malenkov |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
38 |
*/ |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
39 |
|
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
40 |
public class Test8017492 { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
41 |
public static void main(String[] args) throws Exception { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
42 |
Runnable task = new Runnable() { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
43 |
@Override |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
44 |
public void run() { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
45 |
try { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
46 |
SunToolkit.createNewAppContext(); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
47 |
DTD dtd = DTD.getDTD("dtd"); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
48 |
dtd.elements = new Vector<Element>() { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
49 |
@Override |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
50 |
public synchronized int size() { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
51 |
return Integer.MAX_VALUE; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
52 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
53 |
}; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
54 |
dtd.getElement("element"); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
55 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
56 |
catch (Exception exception) { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
57 |
throw new Error("unexpected", exception); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
58 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
59 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
60 |
}; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
61 |
// run task with different AppContext |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
62 |
Thread thread = new Thread(new ThreadGroup("$$$"), task); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
63 |
thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
64 |
@Override |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
65 |
public void uncaughtException(Thread thread, Throwable throwable) { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
66 |
throwable.printStackTrace(); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
67 |
System.exit(1); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
68 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
69 |
}); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
70 |
thread.start(); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
71 |
thread.join(); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
72 |
// add error handling |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
73 |
HTMLDocument document = new HTMLDocument() { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
74 |
@Override |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
75 |
public HTMLEditorKit.ParserCallback getReader(int pos) { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
76 |
return getReader(pos, 0, 0, null); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
77 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
78 |
|
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
79 |
@Override |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
80 |
public HTMLEditorKit.ParserCallback getReader(int pos, int popDepth, int pushDepth, HTML.Tag insertTag) { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
81 |
return new HTMLDocument.HTMLReader(pos, popDepth, pushDepth, insertTag) { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
82 |
@Override |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
83 |
public void handleError(String error, int pos) { |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
84 |
throw new Error(error); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
85 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
86 |
}; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
87 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
88 |
}; |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
89 |
// run parser |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
90 |
new HTMLEditorKit().insertHTML(document, 0, "<html><body>text", 0, 0, null); |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
91 |
} |
12a1993f109b
8017492: Static field in HTML parser affects all applications
malenkov
parents:
diff
changeset
|
92 |
} |