This area was extensively changed in 5.0.3 (when it's out this weekend but you 
can get it from the SVN), it would be worth to see if the problem is already 
fixed.

Paulo 

-----Original Message-----
From: Gylfi Ingvason [mailto:[email protected]] 
Sent: Wednesday, August 04, 2010 4:52 PM
To: [email protected]
Subject: [iText-questions] Null pointer exception in PdfWriter

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


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.


------------------------------------------------------------------------------
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
[email protected]
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