8150187: NPE expected if the system identifier is null for CatalogResolver
Reviewed-by: rriggs, lancea
--- a/jaxp/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java Thu Jun 02 23:26:41 2016 -0700
+++ b/jaxp/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/jaxp/test/javax/xml/jaxp/libs/catalog/ResolutionChecker.java Thu Jun 02 23:26:41 2016 -0700
+++ b/jaxp/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/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java Thu Jun 02 23:26:41 2016 -0700
+++ b/jaxp/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.