Gents,

I'm using an older version of iTextSharp (4.1.6 equivalent), and recently
ran into a null pointer exception in PdfWriter while splitting a PDF file.
Never seen this before despite running all kinds of data for years. The
error happens on the PdfDocument Close() call, that leads to a
RotateAnnotations call, that calls writer.AddToBody, and eventually
GetNewObjectNumber in the PdfWriter is called and that method looks like
this:

protected internal virtual int GetNewObjectNumber(PdfReader reader, int
number, int generation) {
    return currentPdfReaderInstance.GetNewObjectNumber(number, generation);
}

At the time the call is made, the currentPdfReaderInstance is null causing
the exception. I looked at the code in the repository for the latest, and
this method has not changed. I patched the code to check for null as such:

protected internal virtual int GetNewObjectNumber(PdfReader reader, int
number, int generation) {

    if (currentPdfReaderInstance == null) {
        currentPdfReaderInstance = reader.GetPdfReaderInstance(this);
    }

    return currentPdfReaderInstance.GetNewObjectNumber(number, generation);
}

This creates proper output. My question is, is this an acceptable patch or
should this be handled differently? Furthermore, it worries me that this has
not come up before - is it normal that the currentPdfReaderInstance is null
under these circumstances? I have not tried this under 5.0.2 but I suspect
that the same thing will happen - would it make sense to patch the latest?

Any feedback would be appreciated.

Thanks - Gylfi



------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to