# HG changeset patch # User alanb # Date 1355928813 0 # Node ID eded175efec274dc7ba5af3e1ff8122ae985f0bf # Parent 1d01112e9ce51e6e99014e02106a5098b38ff4ed 8005248: (props) Integrate small footprint parser into Properties Reviewed-by: joehw, mchung, psandoz, erikj diff -r 1d01112e9ce5 -r eded175efec2 jdk/make/jdk/Makefile --- a/jdk/make/jdk/Makefile Wed Dec 19 12:09:10 2012 +0000 +++ b/jdk/make/jdk/Makefile Wed Dec 19 14:53:33 2012 +0000 @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 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 @@ -23,16 +23,18 @@ # questions. # -# -# Makefile for building all of java -# - BUILDDIR = .. +PACKAGE = jdk PRODUCT = jdk +JAVAC_LINT_OPTIONS=-Xlint:all include $(BUILDDIR)/common/Defs.gmk -SUBDIRS = asm -include $(BUILDDIR)/common/Subdirs.gmk +# +# Files to compile +# +AUTO_FILES_JAVA_DIRS = jdk -all build clean clobber:: - $(SUBDIRS-loop) +# +# Rules +# +include $(BUILDDIR)/common/Classes.gmk diff -r 1d01112e9ce5 -r eded175efec2 jdk/make/jdk/asm/Makefile --- a/jdk/make/jdk/asm/Makefile Wed Dec 19 12:09:10 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -# -# Copyright (c) 1995, 2012, 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. Oracle designates this -# particular file as subject to the "Classpath" exception as provided -# by Oracle in the LICENSE file that accompanied this code. -# -# 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. -# - -BUILDDIR = ../.. -PACKAGE = jdk.internal.org.objectweb.asm -PRODUCT = jdk -JAVAC_LINT_OPTIONS=-Xlint:all -include $(BUILDDIR)/common/Defs.gmk - -# -# Files to compile -# -AUTO_FILES_JAVA_DIRS = jdk/internal/org/objectweb/asm - -# -# Rules -# -include $(BUILDDIR)/common/Classes.gmk diff -r 1d01112e9ce5 -r eded175efec2 jdk/src/share/classes/java/util/Properties.java --- a/jdk/src/share/classes/java/util/Properties.java Wed Dec 19 12:09:10 2012 +0000 +++ b/jdk/src/share/classes/java/util/Properties.java Wed Dec 19 14:53:33 2012 +0000 @@ -1188,7 +1188,7 @@ provider = loadProviderAsService(cl); if (provider != null) return provider; - throw new InternalError("No fallback"); + return new jdk.internal.util.xml.BasicXmlPropertiesProvider(); }}); } diff -r 1d01112e9ce5 -r eded175efec2 jdk/src/share/classes/jdk/internal/util/xml/BasicXmlPropertiesProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/src/share/classes/jdk/internal/util/xml/BasicXmlPropertiesProvider.java Wed Dec 19 14:53:33 2012 +0000 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package jdk.internal.util.xml; + +import java.util.Properties; +import java.util.InvalidPropertiesFormatException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +import sun.util.spi.XmlPropertiesProvider; + +/** + * A {@code XmlPropertiesProvider} implementation that uses the UKit XML parser. + */ + +public class BasicXmlPropertiesProvider extends XmlPropertiesProvider { + + private final PropertiesDefaultHandler handler = new PropertiesDefaultHandler(); + + public BasicXmlPropertiesProvider() { } + + @Override + public void load(Properties props, InputStream in) + throws IOException, InvalidPropertiesFormatException + { + handler.load(props, in); + } + + @Override + public void store(Properties props, OutputStream os, String comment, + String encoding) + throws IOException + { + handler.store(props, os, comment, encoding); + } +} diff -r 1d01112e9ce5 -r eded175efec2 jdk/test/java/util/Properties/LoadAndStoreXML.java --- a/jdk/test/java/util/Properties/LoadAndStoreXML.java Wed Dec 19 12:09:10 2012 +0000 +++ b/jdk/test/java/util/Properties/LoadAndStoreXML.java Wed Dec 19 14:53:33 2012 +0000 @@ -23,13 +23,16 @@ /* * @test - * @bug 8000354 8000685 + * @bug 8000354 8000685 8004371 * @summary Basic test of storeToXML and loadToXML + * @run main LoadAndStoreXML + * @run main/othervm -Dsun.util.spi.XmlPropertiesProvider=jdk.internal.util.xml.BasicXmlPropertiesProvider LoadAndStoreXML */ import java.io.*; import java.util.*; import java.security.*; +import java.nio.file.*; public class LoadAndStoreXML { @@ -67,6 +70,8 @@ * read with Properties#loadFromXML. */ static void testLoadAndStore(String encoding) throws IOException { + System.out.println("testLoadAndStore, encoding=" + encoding); + Properties props = new Properties(); props.put("k1", "foo"); props.put("k2", "bar"); @@ -89,6 +94,8 @@ * Test loadFromXML with a document that does not have an encoding declaration */ static void testLoadWithoutEncoding() throws IOException { + System.out.println("testLoadWithoutEncoding"); + Properties expected = new Properties(); expected.put("foo", "bar"); @@ -107,10 +114,11 @@ } } - /** - * Test loadFromXML with unsupported encoding - */ - static void testLoadWithBadEncoding() throws IOException { + /** + * Test loadFromXML with unsupported encoding + */ + static void testLoadWithBadEncoding() throws IOException { + System.out.println("testLoadWithBadEncoding"); String s = "" + "" + "" + @@ -128,6 +136,7 @@ * Test storeToXML with unsupported encoding */ static void testStoreWithBadEncoding() throws IOException { + System.out.println("testStoreWithBadEncoding"); Properties props = new Properties(); props.put("foo", "bar"); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -137,6 +146,26 @@ } catch (UnsupportedEncodingException expected) { } } + /** + * Test loadFromXML with malformed documents + */ + static void testLoadWithMalformedDoc(Path dir) throws IOException { + try (DirectoryStream stream = Files.newDirectoryStream(dir, "*.xml")) { + for (Path file: stream) { + System.out.println("testLoadWithMalformedDoc, file=" + file.getFileName()); + try (InputStream in = Files.newInputStream(file)) { + Properties props = new Properties(); + try { + props.loadFromXML(in); + throw new RuntimeException("InvalidPropertiesFormatException not thrown"); + } catch (InvalidPropertiesFormatException x) { + System.out.println(x); + } + } + } + } + } + public static void main(String[] args) throws IOException { testLoadAndStore("UTF-8"); @@ -145,6 +174,12 @@ testLoadWithBadEncoding(); testStoreWithBadEncoding(); + // malformed documents + String src = System.getProperty("test.src"); + String subdir = "invalidxml"; + Path dir = (src == null) ? Paths.get(subdir) : Paths.get(src, subdir); + testLoadWithMalformedDoc(dir); + // re-run sanity test with security manager Policy orig = Policy.getPolicy(); Policy p = new SimplePolicy(new RuntimePermission("setSecurityManager"), diff -r 1d01112e9ce5 -r eded175efec2 jdk/test/java/util/Properties/invalidxml/BadCase.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/Properties/invalidxml/BadCase.xml Wed Dec 19 14:53:33 2012 +0000 @@ -0,0 +1,9 @@ + + + + + + +bar +baz + diff -r 1d01112e9ce5 -r eded175efec2 jdk/test/java/util/Properties/invalidxml/BadDocType.xml.excluded --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/Properties/invalidxml/BadDocType.xml.excluded Wed Dec 19 14:53:33 2012 +0000 @@ -0,0 +1,9 @@ + + + + + + +bar +baz + diff -r 1d01112e9ce5 -r eded175efec2 jdk/test/java/util/Properties/invalidxml/NoClosingTag.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/Properties/invalidxml/NoClosingTag.xml Wed Dec 19 14:53:33 2012 +0000 @@ -0,0 +1,8 @@ + + + + + + +bar +baz diff -r 1d01112e9ce5 -r eded175efec2 jdk/test/java/util/Properties/invalidxml/NoDocType.xml.excluded --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/Properties/invalidxml/NoDocType.xml.excluded Wed Dec 19 14:53:33 2012 +0000 @@ -0,0 +1,8 @@ + + + + + +bar +baz + diff -r 1d01112e9ce5 -r eded175efec2 jdk/test/java/util/Properties/invalidxml/NoRoot.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/Properties/invalidxml/NoRoot.xml Wed Dec 19 14:53:33 2012 +0000 @@ -0,0 +1,4 @@ + + + + diff -r 1d01112e9ce5 -r eded175efec2 jdk/test/java/util/Properties/invalidxml/NotQuoted.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/Properties/invalidxml/NotQuoted.xml Wed Dec 19 14:53:33 2012 +0000 @@ -0,0 +1,9 @@ + + + + + + +bar +baz + diff -r 1d01112e9ce5 -r eded175efec2 jdk/test/java/util/Properties/invalidxml/README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/util/Properties/invalidxml/README.txt Wed Dec 19 14:53:33 2012 +0000 @@ -0,0 +1,5 @@ + +This directory contains test cases for the LoadAndStoreXML test case. Each file +in this directory should be a malformed XML document that should cause the +java.util.Properties loadFromXML method to throw InvalidPropertiesFormatException. +