Project

Profile

Help

Bug #5375

closed

ArrayIndexOutOfBoundsException in NamespaceMap

Added by Taras Chervinka almost 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2022-03-08
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, 11, trunk
Fix Committed on Branch:
10, 11, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

net.sf.saxon.om.NamespaceMap#getDifferences throws ArrayIndexOutOfBoundsException

variables seen in debug:

this = {NamespaceMap@39060} Object is being initialized
 prefixes = {String[2]@39064} ["abp", "wsp"]
 uris = {String[2]@39063} ["http://schemas....", "http://schemas...."]
other = {NamespaceMap@39061} "wsa=http://www.w3.org/2005/08/addressing "
 prefixes = {String[1]@39065} ["wsa"]
  0 = {String@39044} "wsa"
 uris = {String[1]@39067} ["http://www.w3.o..."]
addUndeclarations = false

The class fails at this IF statement as i=1 while there is only one element in array

else {
               if (addUndeclarations || other.prefixes[i].isEmpty()) {
                  result.add(new NamespaceBinding(other.prefixes[j], ""));
               }

               ++j;
            }

also I see that 10.5, 10.6 had this.prefixes[i] in the same IF statement:

else {
               if (addUndeclarations || this.prefixes[i].isEmpty()) {
                  result.add(new NamespaceBinding(other.prefixes[j], ""));
               }

               ++j;
            }
Actions #1

Updated by Taras Chervinka almost 3 years ago

forgot to add this is seen in 10.7 ee java

Actions #3

Updated by Taras Chervinka almost 3 years ago

I think j should be used: if (addUndeclarations || other.prefixes[i].isEmpty()) {

Actions #4

Updated by Taras Chervinka over 2 years ago

TransformerFactory transformerFactory = new net.sf.saxon.TransformerFactoryImpl();
      DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
      documentFactory.setNamespaceAware(true);
      InputSource stub = new InputSource(new StringReader("<a xmlns:abc=\"a\" />"));
      Document document = documentFactory.newDocumentBuilder().parse(stub);
      DOMResult result = new DOMResult(document.getDocumentElement());
      String xml = "<X xmlns:ab=\"b\" xmlns:ac=\"c\"/>";
      transformerFactory.newTransformer().transform(new StreamSource(
            new StringReader(xml)), result);
      StringWriter sw = new StringWriter();
      transformerFactory.newTransformer().transform(new DOMSource(document), new StreamResult(sw));
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
	at net.sf.saxon.om.NamespaceMap.getDifferences(NamespaceMap.java:507)
	at net.sf.saxon.dom.DOMWriter.startElement(DOMWriter.java:162)
	at net.sf.saxon.event.TreeReceiver.startElement(TreeReceiver.java:147)
	at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:379)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:351)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:613)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3132)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:852)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
	at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:439)
	at net.sf.saxon.event.Sender.send(Sender.java:168)
	at net.sf.saxon.jaxp.IdentityTransformer.transform(IdentityTransformer.java:370)
	at test.testSaxonTransformer.main(testSaxonTransformer.java:35)
Actions #5

Updated by Michael Kay over 2 years ago

  • Category set to Internals
  • Status changed from New to In Progress
  • Assignee set to Michael Kay
  • Priority changed from Low to Normal
  • Applies to branch 11, trunk added
  • Fix Committed on Branch 10, 11, trunk added
  • Platforms .NET, Java added

Confirmed that the proposed fix works for this test case; I now need to regression test it, especially to revisit the original bug 5196.

Thanks for your detective work in tracking this down.

Actions #6

Updated by Michael Kay over 2 years ago

  • Status changed from In Progress to Resolved
Actions #7

Updated by O'Neil Delpratt over 2 years ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 10.8 added

Bug fix applied in the Saxon 10.8 maintenance release. (Leaving open awaiting Saxon 11 maintenance release.)

Actions #8

Updated by O'Neil Delpratt over 2 years ago

  • Status changed from Resolved to Closed
  • Fixed in Maintenance Release 11.3 added
  • Fixed in Maintenance Release deleted (10.8)

Bug fix applied in the Saxon 11.3 maintenance release.

Actions #9

Updated by O'Neil Delpratt over 2 years ago

  • Fixed in Maintenance Release 10.8 added

Please register to edit this issue

Also available in: Atom PDF