1 /*
   2  * Copyright (c) 2003, 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 package test.gaptest;
  24 
  25 import static jaxp.library.JAXPTestUtilities.filenameToURL;
  26 import static test.gaptest.GapTestConst.XML_DIR;
  27 
  28 import java.io.IOException;
  29 
  30 import javax.xml.XMLConstants;
  31 import javax.xml.parsers.ParserConfigurationException;
  32 import javax.xml.parsers.SAXParser;
  33 import javax.xml.parsers.SAXParserFactory;
  34 
  35 import org.testng.annotations.Listeners;
  36 import org.testng.annotations.Test;
  37 import org.xml.sax.ErrorHandler;
  38 import org.xml.sax.InputSource;
  39 import org.xml.sax.SAXException;
  40 import org.xml.sax.SAXParseException;
  41 import org.xml.sax.XMLReader;
  42 
  43 /*
  44  * @test
  45  * @bug 4848653
  46  * @library /javax/xml/jaxp/libs
  47  * @run testng/othervm -DrunSecMngr=true test.gaptest.Bug4848653
  48  * @run testng/othervm test.gaptest.Bug4848653
  49  * @summary Verify JAXP schemaLanguage property is ignored if setValidating(false)
  50  */
  51 @Listeners({jaxp.library.FilePolicy.class})
  52 public class Bug4848653 {
  53 
  54     @Test
  55     public void test() throws IOException, SAXException, ParserConfigurationException {
  56         SAXParserFactory factory = SAXParserFactory.newInstance();
  57         factory.setValidating(false);
  58         SAXParser parser = factory.newSAXParser();
  59         parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", XMLConstants.W3C_XML_SCHEMA_NS_URI);
  60 
  61         String filename = XML_DIR + "Bug4848653.xml";
  62         InputSource is = new InputSource(filenameToURL(filename));
  63         XMLReader xmlReader = parser.getXMLReader();
  64         xmlReader.setErrorHandler(new MyErrorHandler());
  65         xmlReader.parse(is);
  66     }
  67 
  68     class MyErrorHandler implements ErrorHandler {
  69         public void error(SAXParseException exception) throws SAXParseException {
  70             throw exception;
  71         }
  72 
  73         public void warning(SAXParseException exception) throws SAXParseException {
  74             throw exception;
  75         }
  76 
  77         public void fatalError(SAXParseException exception) throws SAXParseException {
  78             throw exception;
  79         }
  80 
  81     }
  82 
  83 }
  84