Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-2229

thread safe issue caused by XMLOutputFactoryImpl

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.3
    • Fix Version/s: 2.2.2, 2.1.6
    • Component/s: WS-* Components
    • Labels:
      None

      Description

      Currently CXF calls StaxUtils.getXMLOutputFactory() to get the cached instance of XMLOutputFactoryImpl. But XMLOutputFactoryImpl.createXMLStreamWriter is not thread-safe. See below.

      javax.xml.stream.XMLStreamWriter createXMLStreamWriter(javax.xml.transform.stream.StreamResult sr, String encoding) throws javax.xml.stream.XMLStreamException {
      try{
      if(fReuseInstance && fStreamWriter != null && fStreamWriter.canReuse() && !fPropertyChanged)

      { fStreamWriter.reset(); fStreamWriter.setOutput(sr, encoding); if(DEBUG)System.out.println("reusing instance, object id : " + fStreamWriter); return fStreamWriter; }

      return fStreamWriter = new XMLStreamWriterImpl(sr, encoding, new PropertyManager(fPropertyManager)); – this is not thread safe, since the new instance is assigned to the field fStreamWriter first, then it is possible that different threads get the same XMLStreamWriterImpl when they call this method at the same time.
      }catch(java.io.IOException io)

      { throw new XMLStreamException(io); }

      }

      The solution might be, StaxUtils.getXMLOutputFactory() method creates a new instance of XMLOutputFactory every time, don't cache it.

        Attachments

          Activity

            People

            • Assignee:
              dkulp Daniel Kulp
              Reporter:
              leonw leon wu
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: