You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "leon wu (JIRA)" <ji...@apache.org> on 2009/05/21 11:03:45 UTC

[jira] Created: (CXF-2229) thread safe issue caused by XMLOutputFactoryImpl

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.


[jira] Resolved: (CXF-2229) thread safe issue caused by XMLOutputFactoryImpl

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2229?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Kulp resolved CXF-2229.
------------------------------

       Resolution: Fixed
    Fix Version/s: 2.2.2
                   2.1.6
         Assignee: Daniel Kulp

> 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
>            Assignee: Daniel Kulp
>             Fix For: 2.1.6, 2.2.2
>
>
> 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.


[jira] Commented: (CXF-2229) thread safe issue caused by XMLOutputFactoryImpl

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2229?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12711686#action_12711686 ] 

Daniel Kulp commented on CXF-2229:
----------------------------------

Hmmm....   definitiely a good reason to use woodstox instead of the sun parser.    Woodstox is thread safe in this instance.   I'll add a sync block or similar.

Creating a new factory is VERY expensive and not something you want to do for each call.



> 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.