Search code examples
javaitextibm-midrangerpgle

Exception referring # START NON-TRANSLATABLE while working with java itext and IBM i RPG ILE


working with java itext library, with a very simple test. Code passes but when closing document, it fails due to null pointer exception with java.lang.String.compareToIgnoreCase.

It happens while embedding itext java code into IBM i RPGIV code. Not sure yet if it is a JNI/RPGIV conversion problem (utf8 should be converted to EBCDIC native charset) or a proper itext issue. It would help if any itext developer could confirm me if it could be a typical itext issue or not sounds like that, specially the reference to START NON-TRANSLATABLE.

Exception in thread "main"# START NON-TRANSLATABLEjava.lang.NullPointerException at java.lang.String.compareToIgnoreCase(String.java:603)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:94) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:152)
at com.itextpdf.text.pdf.OutputStreamCounter.flush(OutputStreamCounter.java:89) at com.itextpdf.text.DocWriter.close(DocWriter.java:233)
at com.itextpdf.text.pdf.PdfWriter.close(PdfWriter.java:1341)
at com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:901)
at com.itextpdf.text.Document.close(Document.java:415)

This is my Plex Action diagram code:

enter image description here

Document RPG prototype: enter image description here

PdfWriter RPG prototype: enter image description here Method Document.open: enter image description here Class Element Paragraph: enter image description here Paragraph constructor RPG Prototype enter image description here Element interface (Paragraph implements Element): enter image description here Add paragraph to document method: enter image description here Document close method: enter image description here

These are my Plex API implemented:

Create document:

enter image description here

create PdfWriter:

enter image description here

Open document:

enter image description here

create paragraph:

enter image description here

add paragraph to document

add paragraph to document

Close document:

enter image description here

Finally, I start java with these values: classpath = full list of libraries (itext + Apache POI, all running) java_home = path to java 7


Solution

  • Finally solved, after testing itext on IBM i in plain java. It worked today, and give me directions to locate the embedded itext issue. It was the PdfWriter class which was improperly used. I converted a EBCDIC string to jstring, and then assigned a FileOutputStream object without conversion. Getting a FileOutputStream object from jstring passed the right file object to PdfWriter. The procedure looks now as follows:

      /free
         PhraseString = new_String( %trim(&(1:)));
         pdfFilePath = new_FileOutputStream(PhraseString);
         pdfWriter = get_PdfWriter( pdfDocument: pdfFilePath);
      /end-free