mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8150187: NPE expected if the system identifier is null for CatalogResolver
Reviewed-by: rriggs, lancea
This commit is contained in:
parent
46b0a616ea
commit
1023eb3584
3 changed files with 30 additions and 3 deletions
|
@ -51,6 +51,7 @@ final class CatalogResolverImpl implements CatalogResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputSource resolveEntity(String publicId, String systemId) {
|
public InputSource resolveEntity(String publicId, String systemId) {
|
||||||
|
CatalogMessages.reportNPEOnNull("systemId", systemId);
|
||||||
//Normalize publicId and systemId
|
//Normalize publicId and systemId
|
||||||
systemId = Normalizer.normalizeURI(Util.getNotNullOrEmpty(systemId));
|
systemId = Normalizer.normalizeURI(Util.getNotNullOrEmpty(systemId));
|
||||||
publicId = Normalizer.normalizePublicId(Normalizer.decodeURN(Util.getNotNullOrEmpty(publicId)));
|
publicId = Normalizer.normalizePublicId(Normalizer.decodeURN(Util.getNotNullOrEmpty(publicId)));
|
||||||
|
|
|
@ -41,7 +41,7 @@ class ResolutionChecker {
|
||||||
static void checkExtIdResolution(CatalogResolver resolver,
|
static void checkExtIdResolution(CatalogResolver resolver,
|
||||||
String publicId, String systemId, String matchedUri) {
|
String publicId, String systemId, String matchedUri) {
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
resolver.resolveEntity(publicId, systemId).getSystemId(),
|
resolver.resolveEntity(publicId, getNotSpecified(systemId)).getSystemId(),
|
||||||
matchedUri);
|
matchedUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class ResolutionChecker {
|
||||||
* CatalogUriResolver should throw CatalogException.
|
* CatalogUriResolver should throw CatalogException.
|
||||||
*/
|
*/
|
||||||
static void checkNoMatch(CatalogUriResolver resolver) {
|
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 ********** */
|
/* ********** Checks expected exception ********** */
|
||||||
|
@ -108,7 +108,7 @@ class ResolutionChecker {
|
||||||
CatalogResolver resolver, String publicId, String systemId,
|
CatalogResolver resolver, String publicId, String systemId,
|
||||||
Class<T> expectedExceptionClass) {
|
Class<T> expectedExceptionClass) {
|
||||||
expectThrows(expectedExceptionClass, () -> {
|
expectThrows(expectedExceptionClass, () -> {
|
||||||
resolver.resolveEntity(publicId, systemId);
|
resolver.resolveEntity(publicId, getNotSpecified(systemId));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +181,18 @@ class ResolutionChecker {
|
||||||
throw new AssertionError(message);
|
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 {
|
private interface ThrowingRunnable {
|
||||||
void run() throws Throwable;
|
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
|
* @bug 8156845
|
||||||
* Verifies that an URI reference with a urn:publicid is correctly resolved
|
* Verifies that an URI reference with a urn:publicid is correctly resolved
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue