Mercurial > hg > openjdk > jdk9 > jaxp
changeset 936:f8899b1884e2 jdk-9+122
8150187: NPE expected if the system identifier is null for CatalogResolver
Reviewed-by: rriggs, lancea
author | joehw |
---|---|
date | Fri, 03 Jun 2016 11:38:38 -0700 |
parents | e4c7fa4269e1 |
children | 3c19ab8742c1 3abcc11cbdd0 |
files | src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java test/javax/xml/jaxp/libs/catalog/ResolutionChecker.java test/javax/xml/jaxp/unittest/catalog/CatalogTest.java |
diffstat | 3 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java Thu Jun 02 23:26:41 2016 -0700 +++ b/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java Fri Jun 03 11:38:38 2016 -0700 @@ -51,6 +51,7 @@ @Override public InputSource resolveEntity(String publicId, String systemId) { + CatalogMessages.reportNPEOnNull("systemId", systemId); //Normalize publicId and systemId systemId = Normalizer.normalizeURI(Util.getNotNullOrEmpty(systemId)); publicId = Normalizer.normalizePublicId(Normalizer.decodeURN(Util.getNotNullOrEmpty(publicId)));
--- a/test/javax/xml/jaxp/libs/catalog/ResolutionChecker.java Thu Jun 02 23:26:41 2016 -0700 +++ b/test/javax/xml/jaxp/libs/catalog/ResolutionChecker.java Fri Jun 03 11:38:38 2016 -0700 @@ -41,7 +41,7 @@ static void checkExtIdResolution(CatalogResolver resolver, String publicId, String systemId, String matchedUri) { Assert.assertEquals( - resolver.resolveEntity(publicId, systemId).getSystemId(), + resolver.resolveEntity(publicId, getNotSpecified(systemId)).getSystemId(), matchedUri); } @@ -95,7 +95,7 @@ * CatalogUriResolver should throw CatalogException. */ static void checkNoMatch(CatalogUriResolver resolver) { - resolver.resolve("http://uri/noMatch/docNoMatch.dtd", null); + resolver.resolve("http://uri/noMatch/docNoMatch.dtd", getNotSpecified(null)); } /* ********** Checks expected exception ********** */ @@ -108,7 +108,7 @@ CatalogResolver resolver, String publicId, String systemId, Class<T> expectedExceptionClass) { expectThrows(expectedExceptionClass, () -> { - resolver.resolveEntity(publicId, systemId); + resolver.resolveEntity(publicId, getNotSpecified(systemId)); }); } @@ -181,6 +181,18 @@ throw new AssertionError(message); } + /* + * SystemId can never be null in XML. For publicId tests, if systemId is null, + * it will be considered as not-specified instead. A non-existent systemId + * is returned to make sure there's no match by the systemId. + */ + private static String getNotSpecified(String systemId) { + if (systemId == null) { + return "not-specified-systemId.dtd"; + } + return systemId; + } + private interface ThrowingRunnable { void run() throws Throwable; }
--- a/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java Thu Jun 02 23:26:41 2016 -0700 +++ b/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java Fri Jun 03 11:38:38 2016 -0700 @@ -69,6 +69,20 @@ } /* + * @bug 8150187 + * NPE is expected if the systemId is null. The specification for systemId + * is as follows: + * A system identifier is required on all external entities. XML + * requires a system identifier on all external entities, so this value is + * always specified. + */ + @Test(expectedExceptions = NullPointerException.class) + public void sysIdCantBeNull() { + CatalogResolver catalogResolver = CatalogManager.catalogResolver(CatalogFeatures.defaults()); + InputSource is = catalogResolver.resolveEntity("-//FOO//DTD XML Dummy V0.0//EN", null); + } + + /* * @bug 8156845 * Verifies that an URI reference with a urn:publicid is correctly resolved * with an uri entry with a publicId.