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

Oxygen general issues.
SSC
Posts: 206
Joined: Thu Dec 01, 2011 4:22 pm
Location: Hamburg, Germany

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

Post 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
Simon Scholz
vogella GmbH
http://www.vogella.com
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

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

Post 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
Mihaela Calotescu
http://www.oxygenxml.com
SSC
Posts: 206
Joined: Thu Dec 01, 2011 4:22 pm
Location: Hamburg, Germany

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

Post 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
Simon Scholz
vogella GmbH
http://www.vogella.com
vanakenm
Posts: 4
Joined: Thu Jun 12, 2014 11:17 am

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

Post 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
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

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

Post 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).
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply