JDK-8215330 : javax.xml.catalog.CatalogResolverImpl: GroupEntry.matchURI fails to match
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 11,12
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2018-12-12
  • Updated: 2019-09-09
  • Resolved: 2019-01-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 12 JDK 13
11.0.3-oracleFixed 12.0.1Fixed 13 b03Fixed
Description
ADDITIONAL SYSTEM INFORMATION :
Tested JDK 9, JDK 10.0.2, OpenJDK 11.0.1

A DESCRIPTION OF THE PROBLEM :
An XML <Catalog> with a <group> of <uriSuffix> matchers fails to match.
Match succeeds if similar matcher is not in a <group>.

Possible diagnosis:

Stepping through the code, the problem appears to be with javax.xml.catalog.CatalogResolverImpl, specifically in javax.xml.catalog.GroupEntry.matchURI.   

  GroupEntry.matchURI: 376
  Util.resolve: 94
  CatalogResolverImpl.resolve: 143
  
The REWRITEURI and URISUFFIX cases set both the match and the length of the match, but the GROUP case only sets the match, not the length.  Therefore, upon exiting the loop, the length is still zero, and it behaves as if there was no match.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run test files given below.
src/main/java/XmlCatalogURISuffixFailsInGroup.java
src/main/resources/XmlCatalogURISuffixFailsInGroup.xml

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Runs with no exceptions thrown.
ACTUAL -
javax.xml.catalog.CatalogException: JAXP09040002: No match found for href 'http://www.example.com/B/CommonFileB1.xml' and base 'null'.
	at java.xml/javax.xml.catalog.CatalogMessages.reportError(CatalogMessages.java:74)
	at java.xml/javax.xml.catalog.CatalogResolverImpl.resolve(CatalogResolverImpl.java:153)
	at XMLCatalogURISuffixFailsInGroup.testB1_groupWithoutBase(XMLCatalogURISuffixFailsInGroup.java:45)
	at XMLCatalogURISuffixFailsInGroup.main(XMLCatalogURISuffixFailsInGroup.java:19)


---------- BEGIN SOURCE ----------
---- Java: XmlCatalogURISuffixFailsInGroup.java ----
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.MissingResourceException;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogManager;
import javax.xml.catalog.CatalogResolver;
import javax.xml.transform.Source;

public class XMLCatalogURISuffixFailsInGroup {
  public static void main(String[] ignore) throws MissingResourceException {
    XMLCatalogURISuffixFailsInGroup tst = new XMLCatalogURISuffixFailsInGroup();
    tst.setup();

    try { tst.testA1_noGroup(); }
    catch (Throwable th) { th.printStackTrace(); }

    try { tst.testB1_groupWithoutBase(); }
    catch (Throwable th) { th.printStackTrace(); }

    try { tst.testC1_groupWithBase(); }
    catch (Throwable th) { th.printStackTrace(); }
  }
  private CatalogResolver resolver;

  private void setup() {
    String catalogName = "XMLCatalogURISuffixFailsInGroup.xml";
    URI catalogUri = getResourceURI(catalogName);
    this.resolver =
      CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogUri);
  }

  public void testA1_noGroup() {
    // srcA1 succeeds
    Source srcA1 =
      this.resolver.resolve("http://www.example.com/A/CommonFileA1.xml", null);
    assert srcA1.getSystemId().endsWith("LocalFileA1.xml"): srcA1.getSystemId();
    System.out.println("srcA1: "+srcA1.getSystemId());
    System.out.println();
  }
  public void testB1_groupWithoutBase() {
    // srcB fails because it is in a catalog group
    Source srcB1 =
      this.resolver.resolve("http://www.example.com/B/CommonFileB1.xml", null);
    assert srcB1.getSystemId().endsWith("LocalFileB1.xml"): srcB1.getSystemId();
    System.out.println("srcB1: "+srcB1.getSystemId());
    System.out.println();
  }
  public void testC1_groupWithBase() {
    // srcC1 fails because it is in a catalog group
    Source srcC1 =
      this.resolver.resolve("http://www.example.com/C/CommonFileC1.xml", null);
    assert srcC1.getSystemId().endsWith("LocalFileC1.xml"): srcC1.getSystemId();
    System.out.println("srcC1: "+srcC1.getSystemId());
    System.out.println();
  }

  private static URI getResourceURI(String resourceName)
  throws MissingResourceException {
    Class<?> loader = XMLCatalogURISuffixFailsInGroup.class;

    URL resourceUrl = loader.getResource(resourceName);
    if (resourceUrl == null)
      throw new MissingResourceException(resourceName, loader.getName(), null);

    URI resourceUri;
    try { resourceUri = resourceUrl.toURI(); }
    catch (URISyntaxException never) { throw new AssertionError(never); }

    return resourceUri;
  }

}


---- resource: XmlCatalogURISuffixFailsInGroup.xml ---
<!DOCTYPE catalog
  PUBLIC "-//OASIS//DTD XML Catalogs V1.1//EN" "XML_Catalogs_v1.1.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
         prefer="system" resolve="strict">

  <uriSuffix uriSuffix="/A/CommonFileA1.xml"
	     uri="localMirrorA/LocalFileA1.xml"/>

  <group>
    <uriSuffix uriSuffix="/B/CommonFileB1.xml"
               uri="localMirrorB/LocalFileB1.xml"/>
    <uriSuffix uriSuffix="/B/CommonFileB2.xml"
               uri="localMirrorB/LocalFileB2.xml"/>
  </group>

  <group baseURI="localMirrorC">
    <uriSuffix uriSuffix="/C/CommonFileC1.xml"
               uri="LocalFileC1.xml"/>
    <uriSuffix uriSuffix="/C/CommonFileC2.xml"
               uri="LocalFileC2.xml"/>
  </group>

</catalog>

---------- END SOURCE ----------

FREQUENCY : always



Comments
Fix Request Backporting this fix keep JAXP sane and synced across JDK releases. The patch applies cleanly to 11u, the new test fails without the patch and passes with the patch. Patched 11u also passes all java/xml tests.
18-02-2019

To reproduce the issue, run the attached test case: JDK 11.0.1 - Fail JDK 12-ea+21 - Fail Output: srcA1: file:/D:/Java7Workspace/TestCases/src/localMirrorA/LocalFileA1.xml javax.xml.catalog.CatalogException: JAXP09040002: No match found for href 'http://www.example.com/B/CommonFileB1.xml' and base 'null'. at java.xml/javax.xml.catalog.CatalogMessages.reportError(CatalogMessages.java:74) at java.xml/javax.xml.catalog.CatalogResolverImpl.resolve(CatalogResolverImpl.java:153) at JI9058512.testB1_groupWithoutBase(JI9058512.java:46) at JI9058512.main(JI9058512.java:20) javax.xml.catalog.CatalogException: JAXP09040002: No match found for href 'http://www.example.com/C/CommonFileC1.xml' and base 'null'. at java.xml/javax.xml.catalog.CatalogMessages.reportError(CatalogMessages.java:74) at java.xml/javax.xml.catalog.CatalogResolverImpl.resolve(CatalogResolverImpl.java:153) at JI9058512.testC1_groupWithBase(JI9058512.java:54) at JI9058512.main(JI9058512.java:23)
13-12-2018