Bug 54061 - NullPointer Exception in org.apache.fop.fo.FObj
Summary: NullPointer Exception in org.apache.fop.fo.FObj
Status: NEW
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: general (show other bugs)
Version: 1.1
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-29 07:44 UTC by spao
Modified: 2012-11-05 10:31 UTC (History)
0 users



Attachments
test class to reproduce the error (2.81 KB, text/plain)
2012-10-31 13:53 UTC, spao
Details
FO File that generates the error (51.31 KB, text/plain)
2012-10-31 13:54 UTC, spao
Details
Attached a version of the FO which has been formatted. (72.14 KB, text/x-xslfo)
2012-10-31 16:05 UTC, Robert Meyer
Details
Smaller FO to reproduce the nullpointer (953 bytes, text/x-xslfo)
2012-11-01 14:15 UTC, Robert Meyer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description spao 2012-10-29 07:44:25 UTC
In the method public void removeChild(FONode child) {... i get a NullPointerException at row FObj:250;
I have seen the code:

...
        if (child == lastChild) {
            if (child.siblings != null) {  // row 249
                lastChild = siblings[0];   // row 250
            } else {
                lastChild = null;
            }
        }
...

the row 250 should be lastChild = child.siblings[0] instead of siblings[0] ???
Comment 1 Robert Meyer 2012-10-29 08:41:48 UTC
Would it be possible for you to post an example FO file (and xconf if necessary) to reproduces this error. This will help us investigate why this is happening and also what needs to be done in order to resolve it.
Comment 2 spao 2012-10-29 09:11:59 UTC
(In reply to comment #1)
> Would it be possible for you to post an example FO file (and xconf if
> necessary) to reproduces this error. This will help us investigate why this
> is happening and also what needs to be done in order to resolve it.

(In reply to comment #1)
> Would it be possible for you to post an example FO file (and xconf if
> necessary) to reproduces this error. This will help us investigate why this
> is happening and also what needs to be done in order to resolve it.

Sorry, i can't
Comment 3 Chris Bowditch 2012-10-31 12:02:06 UTC
Is that because of confidentially? If so, please replace the sensitive text with a string of XXX or similar. I'm updating this bug to Needs Info status
Comment 4 spao 2012-10-31 13:53:04 UTC
Created attachment 29533 [details]
test class to reproduce the error

Test Class with main method.
Takes as input the FO file and a boolean strictValidation.
If strictValidation = true gives a standard error of grammar, if it is false instead gives NullPointer on FObj.java
Comment 5 spao 2012-10-31 13:54:58 UTC
Created attachment 29534 [details]
FO File that generates the error
Comment 6 Robert Meyer 2012-10-31 14:55:58 UTC
Hi,

Initially I tried going through the code and implementing the fix you suggested which does appear to be incorrect in the source, but unfortunately it trips up later on with another null pointer exception. I then put in a check for that to avoid it but I got a further NoSuchElement exception. It was at this stage I looked at the FO and the validation warnings I tried to circumvent by using the -r flag. It appears there is a lot wrong with the file. The warnings / errors are all like the following:

"fo:table-body" is missing child elements. Required content model: marker* (table-row+|table-cell+) (See position 895:37)

After looking through the FO there were numerous instances of tables with table-body elements with no contents or similarly declared empty table-headers. These are rules which both FOP and the FO must abide [1], so I can see why FOP is falling over. I went through the FO removing all of the blank tables with the problematic body and header's elements. After I had done this I could successfully render the document. It may not be how it was intended to look, but it did render. 

In order to get yours to render, I would recommend going through the FO file and instead of removing the tables, add the necessary missing table-rows / table-cells if these are used for formatting purposes. This should prevent FOP from complaining whilst allowing you to render the document correctly.

[1] http://www.w3.org/TR/xsl/#fo_table-body

In the meantime, this bug can relate to the incorrect sublings usage you specified in your original post.
Comment 7 Glenn Adams 2012-10-31 15:23:07 UTC
in any case, no matter how broken the FO input, FOP shouldn't be throwing NPEs, so there is an FOP bug to fix... the reporter needs to find the minimal (reduced) test that produces the NPE
Comment 8 spao 2012-10-31 15:32:46 UTC
(In reply to comment #6)
> Hi,
> 
> Initially I tried going through the code and implementing the fix you
> suggested which does appear to be incorrect in the source, but unfortunately
> it trips up later on with another null pointer exception. I then put in a
> check for that to avoid it but I got a further NoSuchElement exception. It
> was at this stage I looked at the FO and the validation warnings I tried to
> circumvent by using the -r flag. It appears there is a lot wrong with the
> file. The warnings / errors are all like the following:
> 
> "fo:table-body" is missing child elements. Required content model: marker*
> (table-row+|table-cell+) (See position 895:37)
> 
> After looking through the FO there were numerous instances of tables with
> table-body elements with no contents or similarly declared empty
> table-headers. These are rules which both FOP and the FO must abide [1], so
> I can see why FOP is falling over. I went through the FO removing all of the
> blank tables with the problematic body and header's elements. After I had
> done this I could successfully render the document. It may not be how it was
> intended to look, but it did render. 
> 
> In order to get yours to render, I would recommend going through the FO file
> and instead of removing the tables, add the necessary missing table-rows /
> table-cells if these are used for formatting purposes. This should prevent
> FOP from complaining whilst allowing you to render the document correctly.
> 
> [1] http://www.w3.org/TR/xsl/#fo_table-body
> 
> In the meantime, this bug can relate to the incorrect sublings usage you
> specified in your original post.

The fact is that I wanted to avoid to fix errors (example: fo: table-body missing childs) in the FO because I thought that strictValidation = false ignored them.
But since FOP gave me NullPointer, so I proceeded as you said, that I corrected all errors as specified in http://www.w3.org/TR/xsl/,
but this cost me a lot of trouble because the FO file is generated on a few lines, but very long, and therefore the error is of the type: "see position 3:56753"!
But how do I find the column 56753? and after that I found it how do I compare it with my XSLT file that is indented?

All this to say:
there is a FOP option to create a FO file indented, which indicates the position of errors based on the file indented?
Thanks a lot
Comment 9 Robert Meyer 2012-10-31 16:05:56 UTC
Created attachment 29535 [details]
Attached a version of the FO which has been formatted.

I ran through the FO using xml_pp (pretty print) in Linux to create the attached output. This probably isn't helpful to you as you are using XSLT and is likely to change. The other alternative may be to use something like:

<xsl:if test="<tag>">
  <fo:table>
  ...
  <xsl:apply-templates select="<tag>"/>
  </fo:table>
</xsl:if>

This way you can check to see if the data exists before adding the table.

With regard to outputting formatted FO, I am not sure on that but maybe someone else will know.

Glen, with regard to adding a smaller example, i'll see if I can replicate the same behaviour by creating a table with an empty table-body. If so, i'll upload that when I get a chance.
Comment 10 Pascal Sancho 2012-10-31 16:14:43 UTC
(In reply to comment #8)
> there is a FOP option to create a FO file indented, which indicates the
> position of errors based on the file indented?

FOP does not produce FO, this is the matter of XSLT engine.
For convenience, FOP comes with xalan.

See [1] to tweak your XSLT if you use xalan.

[1] http://xml.apache.org/xalan-j/usagepatterns.html#outputprops
Comment 11 Robert Meyer 2012-11-01 14:15:48 UTC
Created attachment 29539 [details]
Smaller FO to reproduce the nullpointer

I have attached a smaller example which reproduces the nullpointer reported in the original post when using the -r flag.
Comment 12 spao 2012-11-05 10:31:04 UTC
(In reply to comment #10)
> (In reply to comment #8)
> > there is a FOP option to create a FO file indented, which indicates the
> > position of errors based on the file indented?
> 
> FOP does not produce FO, this is the matter of XSLT engine.
> For convenience, FOP comes with xalan.
> 
> See [1] to tweak your XSLT if you use xalan.
> 
> [1] http://xml.apache.org/xalan-j/usagepatterns.html#outputprops

Ok, thanks, solved.