cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "leon wu (JIRA)" <j...@apache.org>
Subject [jira] Created: (CXF-2229) thread safe issue caused by XMLOutputFactoryImpl
Date Thu, 21 May 2009 09:03:45 GMT
thread safe issue caused by XMLOutputFactoryImpl
------------------------------------------------

                 Key: CXF-2229
                 URL: https://issues.apache.org/jira/browse/CXF-2229
             Project: CXF
          Issue Type: Bug
          Components: WS-* Components
    Affects Versions: 2.1.3
            Reporter: leon wu


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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message