1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package dom;
25
26 import javax.xml.parsers.DocumentBuilder;
27 import javax.xml.parsers.DocumentBuilderFactory;
28 import javax.xml.parsers.ParserConfigurationException;
29
30 import org.testng.Assert;
31 import org.testng.annotations.Test;
32 import org.w3c.dom.DOMConfiguration;
33 import org.w3c.dom.DOMError;
34 import org.w3c.dom.DOMErrorHandler;
35 import org.w3c.dom.Document;
36 import org.w3c.dom.Element;
37 import org.w3c.dom.Text;
38
39 /*
40 * @bug 6520131
41 * @summary Test DOMErrorHandler reports an error for invalid character.
42 */
43 public class Bug6520131 {
44
45 @Test
46 public void test() {
47 String string = new String("\u0001");
48
49 try {
50 // create document
51 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
52 DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
53 Document document = documentBuilder.newDocument();
54
55 DOMConfiguration domConfig = document.getDomConfig();
56 domConfig.setParameter("well-formed", Boolean.TRUE);
57 domConfig.setParameter("error-handler", new DOMErrorHandler() {
58 public boolean handleError(DOMError e) {
59 throw new RuntimeException(e.getMessage());
60 }
61 });
62
|
1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package dom;
25
26 import javax.xml.parsers.DocumentBuilder;
27 import javax.xml.parsers.DocumentBuilderFactory;
28 import javax.xml.parsers.ParserConfigurationException;
29
30 import org.testng.Assert;
31 import org.testng.annotations.Listeners;
32 import org.testng.annotations.Test;
33 import org.w3c.dom.DOMConfiguration;
34 import org.w3c.dom.DOMError;
35 import org.w3c.dom.DOMErrorHandler;
36 import org.w3c.dom.Document;
37 import org.w3c.dom.Element;
38 import org.w3c.dom.Text;
39
40 /*
41 * @bug 6520131
42 * @summary Test DOMErrorHandler reports an error for invalid character.
43 */
44 @Listeners({jaxp.library.BasePolicy.class})
45 public class Bug6520131 {
46
47 @Test
48 public void test() {
49 String string = new String("\u0001");
50
51 try {
52 // create document
53 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
54 DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
55 Document document = documentBuilder.newDocument();
56
57 DOMConfiguration domConfig = document.getDomConfig();
58 domConfig.setParameter("well-formed", Boolean.TRUE);
59 domConfig.setParameter("error-handler", new DOMErrorHandler() {
60 public boolean handleError(DOMError e) {
61 throw new RuntimeException(e.getMessage());
62 }
63 });
64
|