Page 1 of 1

OpenDoPE - ConcurrentModificationException error

PostPosted: Sat Oct 01, 2011 8:45 am
by ls008
Hi,

I am using 2.6.0 version. I convert templates with custom xml data and content controls (also repeats) using the OpenDoPEHandler.preprocess(wordMLPackage)
BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart()).

Recently I get a ConcurrentModificationException error sometime, not always. Following is the error:

java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at com.sun.xml.bind.v2.runtime.reflect.Lister$CollectionLister$1.next(Lister.java:284)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:135)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:324)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)
at org.docx4j.XmlUtils.marshaltoString(XmlUtils.java:406)
at org.docx4j.XmlUtils.marshaltoString(XmlUtils.java:350)
at org.docx4j.model.datastorage.OpenDoPEHandler.preprocessRun(OpenDoPEHandler.java:383)
at org.docx4j.model.datastorage.OpenDoPEHandler.preprocess(OpenDoPEHandler.java:119)

How do I fix it and why it's not happening everytime I run the code?

Thanks.

Re: ConcurrentModificationException error

PostPosted: Sun Oct 02, 2011 2:10 pm
by jason
That's odd.

The OpenDoPE code in 2.6.0 was not thread safe, but even so, I would not have expected that error unless you were processing the one WordprocessingMLPackage more than once concurrently, or you were sharing a part (eg MainDocumentPart) between packages (which you shouldn't do).

Please try docx4j 2.7.1-SNAPSHOT: http://www.docx4java.org/docx4j/docx4j- ... 111002.jar
That contains a thread safe version.

How you invoke it has changed slightly:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                // Process conditionals and repeats
                OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage);
                odh.preprocess();
               
                OpenDoPEIntegrity odi = new OpenDoPEIntegrity();
                odi.process(wordMLPackage);
                               
                // Apply the bindings
                BindingHandler.setHyperlinkStyle("hyperlink");                                         
                BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart());
               
                // Strip content controls: you MUST do this
                // if you are processing hyperlinks
                RemovalHandler rh = new RemovalHandler();
                rh.removeSDTs(wordMLPackage, Quantifier.ALL);

                SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
                saver.save(filepathprefix + "_stripped.docx");
 
Parsed in 0.016 seconds, using GeSHi 1.0.8.4


fyi, there is also a simple webapp which does this:

https://github.com/plutext/OpenDoPE-WAR ... tBoth.java

Please do feedback whether suggestions here address your issue. thanks.

cheers .. Jason
ps this topic belongs in the sub-forum. I will move it there in a couple of days.

Re: OpenDoPE - ConcurrentModificationException error

PostPosted: Tue Oct 04, 2011 7:34 am
by ls008
Hi Jason,

Thank you for the reply. I have changed code as you suggested and using docx4j 2.7.1-snapshot. Following is the code:
Code: Select all
protected static void generateDoc(String output_dir, String input_dir, String input_filename, String output_filename, String xml_filename) throws Docx4JException, IOException, Exception
    {
       
      String inputfilepath = input_dir;
      String outputfilepath = output_dir;
      String inputfilename = input_filename;
      String outputfilename = output_filename;
      String xmlfilename = xml_filename;
     
      String itemId = "{0D9B5851-5CF8-4CEC-897E-C8ECB8B9463B}".toLowerCase();
     
      WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath+inputfilename));
      Document data = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(output_dir+xmlfilename);
   
      CustomXmlDataStoragePart customXmlDataStoragePart = (CustomXmlDataStoragePart) wordMLPackage.getCustomXmlDataStorageParts().get(itemId);
      CustomXmlDataStorage customXmlDataStorage = customXmlDataStoragePart.getData();
      customXmlDataStorage.setDocument(data);
 
      // Process conditionals and repeats
      OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage);
      odh.preprocess();
     
      OpenDoPEIntegrity odi = new OpenDoPEIntegrity();
      odi.process(wordMLPackage);
         
      // Apply the bindings
      BindingHandler.setHyperlinkStyle("hyperlink");           
      BindingHandler.applyBindings(wordMLPackage.getMainDocumentPart());
     
      // Strip content controls: you MUST do this
      // if you are processing hyperlinks
      RemovalHandler rh = new RemovalHandler();
      rh.removeSDTs(wordMLPackage, Quantifier.ALL);

      SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
      saver.save(new java.io.File(outputfilepath+outputfilename));   
    }

It compiles ok. But I got a run time error:
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NoSuchMethodError: org.docx4j.model.datastorage.OpenDoPEHandler.<init>(Lorg/docx4j/openpackaging/packages/WordprocessingMLPackage;)V

Re: OpenDoPE - ConcurrentModificationException error

PostPosted: Tue Oct 04, 2011 9:18 am
by jason
Please forgive the obvious questions, but is your old docx4j jar still on your classpath? Did you put the new one there?

Re: OpenDoPE - ConcurrentModificationException error

PostPosted: Wed Oct 05, 2011 7:43 am
by ls008
My old docx4j jar was removed. My new one is there, otherwise it wouldn't compile.