#55 referencing issue when calling ContentHandler.startElement

SAX_2.0
closed-fixed
nobody
javadoc (14)
5
2004-03-19
2004-03-07
No

Assume you have a org.xml.sax.ContentHandler
implementation, considering the call of the
startElement method.

If you have now several calls to this method, the
Object in the atts parameter (of type Attributes) is
every time the reference to the same Object which is
altered respectively.

That is, if you save these references while
experiencing several startElement events, every saved
reference will point to the same object (which will
then contain the last set of attributes perceived).

As a workaround, when working like this, you currently
need to clone the set of attributes you wish to save;
this behaviour is absolutely counterproductive.

Discussion

  • Anonymous - 2004-03-19
    • labels: 340834 --> javadoc
    • status: open --> closed-fixed
     
  • Anonymous - 2004-03-19

    Logged In: YES
    user_id=44117

    Not a bug, except _maybe_ in terms of javadoc. The
    behavior you're complaining about has been part of SAX
    since the 1.0 days, and has been widely documented.
    (Javadoc now fixed in CVS.)

    The org.xml.sax.helpers.AttributesImpl class is provided
    specifically
    to facilitate this cloning, and there was a SAX 1.0 analogue.

    Forcing the parser to generate a new Attributes object for each
    call would be hideously slow, especially since typical usage
    involves using their values once and then discarding them.

    So as an API policy, only the software that knows the data
    needs to be copied is responsible for copying it.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks