You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2022/12/12 15:31:40 UTC

[daffodil] branch main updated: Deep copy Attributes with SAX performance unparse command

This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new 54bbe40f5 Deep copy Attributes with SAX performance unparse command
54bbe40f5 is described below

commit 54bbe40f503c5e4f3645036a3b66be09121f3785
Author: Steve Lawrence <sl...@apache.org>
AuthorDate: Mon Dec 12 08:30:07 2022 -0500

    Deep copy Attributes with SAX performance unparse command
    
    When running the CLI performance unparse command with the `-I sax`
    option, we deep copy all SAX events and convert them to array of objects
    so we can replay those events in the actual performance loop. This
    avoids the overhead of parsing the XML infoset when testing SAX.
    
    However, we don't currently deep copy the Attributes parameter in the
    startElement function. So if a SAX XMLReader implementation
    reuses/mutates the same Attributes object for multiple calls to
    startEvent (which Xerces does), then all of our StartElement events will
    share the same Attributes object with mutated values, leading to
    unexpected failures.
    
    To fix this, this creates an AttributesImpl object from the Attributes
    object passed into the startElement function, which takes a persistent
    snapshot that is safe to store in our array of events.
    
    DAFFODIL-2400
---
 daffodil-cli/src/main/scala/org/apache/daffodil/InfosetTypes.scala | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/daffodil-cli/src/main/scala/org/apache/daffodil/InfosetTypes.scala b/daffodil-cli/src/main/scala/org/apache/daffodil/InfosetTypes.scala
index 66848940b..375286689 100644
--- a/daffodil-cli/src/main/scala/org/apache/daffodil/InfosetTypes.scala
+++ b/daffodil-cli/src/main/scala/org/apache/daffodil/InfosetTypes.scala
@@ -43,6 +43,7 @@ import org.xml.sax.ContentHandler
 import org.xml.sax.InputSource
 import org.xml.sax.XMLReader
 import org.xml.sax.Locator
+import org.xml.sax.helpers.AttributesImpl
 import org.xml.sax.helpers.DefaultHandler
 
 import org.apache.daffodil.api.DFDL
@@ -598,7 +599,7 @@ case class SAXInfosetHandler(dataProcessor: DataProcessor, forPerformance: Boole
       events += SaxEventStartDocument()
 
     override def startElement(uri: String, localName: String, qName: String, atts: Attributes): Unit =
-      events += SaxEventStartElement(uri, localName, qName, atts)
+      events += SaxEventStartElement(uri, localName, qName, new AttributesImpl(atts))
 
     override def startPrefixMapping(prefix: String, uri: String): Unit =
       events += SaxEventStartPrefixMapping(prefix, uri)