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 parsers; 25 26 import java.io.IOException; 27 28 import javax.xml.parsers.DocumentBuilder; 29 import javax.xml.parsers.DocumentBuilderFactory; 30 import javax.xml.parsers.ParserConfigurationException; 31 32 import org.testng.Assert; 33 import org.testng.annotations.Test; 34 import org.w3c.dom.Document; 35 import org.xml.sax.SAXException; 36 37 /* 38 * @bug 7166896 39 * @summary Test DocumentBuilder.parse(String uri) supports IPv6 format. 40 */ 41 public class Bug7166896Test { 42 43 @Test 44 public void test() throws Exception { 45 final String url = "http://[fe80::la03:73ff:fead:f7b0]/note.xml"; 46 final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); 47 domFactory.setNamespaceAware(true); 48 DocumentBuilder builder; 49 Document doc = null; 50 System.out.println("URL is " + url); 51 try { 52 builder = domFactory.newDocumentBuilder(); 53 // here comes the MalformedURLException. With Java6 / 7 it looks 54 // like this: 55 // java.net.MalformedURLException: For input string: 56 // ":la03:73ff:fead:f7b0%5D" 57 // which is not fine. 58 // with xerces 2.11.0 it complains about a non-existing host, which 59 // is fine 60 System.out.println("passing URL to DocumentBuilder.parse()"); 61 doc = builder.parse(url); 62 63 } catch (SAXException e) { 64 e.printStackTrace(); 65 } catch (IOException e) { 66 String em = e.getMessage(); 67 System.err.println("Error message: " + em); 68 if (em.contains("For input string: \":la03:73ff:fead:f7b0%5D\"")) { 69 Assert.fail("failed to accept IPv6 address"); 70 } 71 } catch (ParserConfigurationException e) { 72 e.printStackTrace(); 73 } 74 75 } 76 }