Page 1 of 1

ro.sync.ecss.extensions.api.node.AuthorNode#getTextContent() throws NullPointer

Posted: Mon Aug 27, 2012 12:39 pm
by SSC
Hello,

the ro.sync.ecss.extensions.api.node.AuthorNode#getTextContent() method throws a NullPointerException.

Code: Select all


java.lang.NullPointerException
at ro.sync.ecss.dom.o.f(Unknown Source)
at ro.sync.ecss.dom.o.getTextContent(Unknown Source)
It occurs in a ro.sync.ecss.extensions.api.StylesFilter, when I try to get the text content of all existing PIs (ro.sync.ecss.extensions.api.node.AuthorNode#NODE_TYPE_PI)

Usually the getTextContent() method should only throw a javax.swing.text.BadLocationException, but not a NullPointerException.
The actual PI content where the NullPointer was thrown is : "tag TT0000014@A.4"
But the document itself contains more of those PIs, which look similar where the NullPointer is not thrown.

Maybe you could have a look at it.

Best regards,

Simon

Re: ro.sync.ecss.extensions.api.node.AuthorNode#getTextContent() throws NullPointer

Posted: Mon Aug 27, 2012 3:53 pm
by mihaela
Hi Simon,

This is a known issue and we work to fix it.
The problem is that a processing instruction node has no content information the first time when the styles are applied on it.

The only thing that you can do for now (until the fix is available) is to catch the NullPointerException and ignore it (this exception will appear only the first time when the filter method is invoked). The filter method will be then called for the same processing instruction node when this will have a content information so your filter code will be applied correctly.

We will let you know when the fix will be available.

Best regards,
Mihaela

Re: ro.sync.ecss.extensions.api.node.AuthorNode#getTextContent() throws NullPointer

Posted: Mon Aug 27, 2012 4:48 pm
by SSC
Hello mihaela,

I also realized that this Exception only occurs at startup and afterwards everything works great.

I just postet this Bug for you in case you have not recognized it yet.

Best regards,

Simon

Re: ro.sync.ecss.extensions.api.node.AuthorNode#getTextConte

Posted: Thu Jun 12, 2014 11:19 am
by vanakenm
Hi Oxygen team,
We just stumbled on exactly the same problem. This is quite old - as this bug been fixed since. If not, is it on your roadmap ? Does the advice of catching the NPE still apply? - it seems to work, I'm just not that keen on catching NPE's in my code.

Thanks,

Martin

Re: ro.sync.ecss.extensions.api.node.AuthorNode#getTextConte

Posted: Thu Jun 12, 2014 3:34 pm
by mihaela
Hi Martin,

Here is the javadoc of the authorNode parameter of the ro.sync.ecss.extensions.api.StylesFilter.filter(Styles, AuthorNode) method:
@param authorNode The node to filter the CSS style for.
If this node points to a processing instruction, a CDATA or a comment then the real node can be
obtained by casting this object to {@link ArtificialNode} and using {@link ArtificialNode#getWrappedNode()}.
This artificial node that wraps the processing instruction node has no content information (it has the processing instruction information stored in attributes) and this is why you get the NPE when calling getTextContent() on it.
What you can do is to check if the node type is AuthorNode.NODE_TYPE_PI before calling the getTextContent() method (the artificial elements have the AuthorNode.NODE_TYPE_ELEMENT type).