Search code examples
coldfusionitextxmlworker

NoSuchMethodError: com.itextpdf.tool.xml.xtra.xfa.js.RhinoJsNodeList.getLength()J at com.itextpdf.tool.xml.xtra.xfa.js.RhinoJsNodeList.append


I'm having one of those "nothing has changed, but we changed a bunch of stuff" problems.

I haven't changed the source code. We DID change servers. When I try to use the FillandFlatten routine from itext xfaworker, I get the error at the bottom of this page. We are running all 5.5.4 version files. I get no errors/warnings when compiling.

I am importing the following (the last two were an attempt to fix this):

import com.allaire.cfx.*;
import com.itextpdf.license.LicenseKey;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.XfaForm;
import com.itextpdf.tool.xml.xtra.xfa.XFAFlattener;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import com.itextpdf.tool.xml.xtra.xfa.js.*;
import com.itextpdf.tool.xml.xtra.xfa.js.RhinoJsNodeList;

Although I am fairly certain that the fix is going to be something I did, I don't know where to look anymore.

ERROR GENERATED: java.lang.NoSuchMethodError: com.itextpdf.tool.xml.xtra.xfa.js.RhinoJsNodeList.getLength()J at com.itextpdf.tool.xml.xtra.xfa.js.RhinoJsNodeList.append(RhinoJsNodeList.java:37) at com.itextpdf.tool.xml.xtra.xfa.js.JsTree.addChild(JsTree.java:94) at com.itextpdf.tool.xml.xtra.xfa.js.JsNode.addChild(JsNode.java:234) at com.itextpdf.tool.xml.xtra.xfa.pipe.DataPipeline.open(DataPipeline.java:70) at com.itextpdf.tool.xml.XMLWorker.startElement(XMLWorker.java:103) at com.itextpdf.tool.xml.parser.XMLParser.startElement(XMLParser.java:371) at com.itextpdf.tool.xml.parser.state.TagEncounteredState.process(TagEncounteredState.java:104) at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:236) at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:214) at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:187) at com.itextpdf.tool.xml.xtra.xfa.XFAFlattener.flatten(XFAFlattener.java:401) at com.itextpdf.tool.xml.xtra.xfa.XFAFlattener.flatten(XFAFlattener.java:282) at com.itextpdf.tool.xml.xtra.xfa.XFAFlattener.flatten(XFAFlattener.java:253) at FillAndFlatten.manipulatePdf(FillAndFlatten.java:125) at FillAndFlatten.processRequest(FillAndFlatten.java:87)

Thank you in advance.


Solution

  • I've seen this problem before in the following context.

    Suppose that you have an application A with a dependency on library B. You have two jars: A-1.0.jar and B-1.0.jar. A-1.0.jar is compiled using B-1.0.jar.

    In version 1.0 of library B, there is a method foo() that returns void:

    public void foo() { ... }
    

    However, in version 2.0, this method is changed in the sense that it now returns int:

    public int foo() { ... }
    

    The name of the method didn't change, but its signature did.

    Now you get a new jar: B-2.0.jar, but if you use A-1.0.jar with B-2.0.jar, you will get a NoSuchMethodError because the method foo() can not be found. In reality, the method foo() is still there, but version 1.0 of application A is looking for public void foo() whereas version 2.0 of library B doesn't know about such a method. It only knows about a method public int foo().

    The only way to solve problems like this, is to recompile application A with the new jar for B into A-2.0.jar. A-1.0.jar won't work with B-2.0.jar, but A-2.0.jar will (even if you didn't change anything to application A).

    DISCLAIMER: this answer is based on the occurrence of a NoSuchMethodError in general. I haven't checked if this explains the specific problem with XFA Worker, but I see that a ticket has been method on the issue tracker at iText Software, which means that one of our engineers will check if my educated guess is correct (if not, that engineer will post an extra answer).