8150187: NPE expected if the system identifier is null for CatalogResolver

Reviewed-by: rriggs, lancea
This commit is contained in:
Joe Wang 2016-06-03 11:38:38 -07:00
parent 46b0a616ea
commit 1023eb3584
3 changed files with 30 additions and 3 deletions
jaxp
src/java.xml/share/classes/javax/xml/catalog
test/javax/xml/jaxp
libs/catalog
unittest/catalog

@ -51,6 +51,7 @@ final class CatalogResolverImpl implements CatalogResolver {
@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)));

@ -41,7 +41,7 @@ class ResolutionChecker {
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 @@ class ResolutionChecker {
* 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 @@ class ResolutionChecker {
CatalogResolver resolver, String publicId, String systemId,
Class<T> expectedExceptionClass) {
expectThrows(expectedExceptionClass, () -> {
resolver.resolveEntity(publicId, systemId);
resolver.resolveEntity(publicId, getNotSpecified(systemId));
});
}
@ -181,6 +181,18 @@ class ResolutionChecker {
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;
}

@ -68,6 +68,20 @@ public class CatalogTest {
}
}
/*
* @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