getFullySelectedNode throws NullPointerException

Oxygen general issues.
Denis
Posts: 47
Joined: Thu Jun 19, 2014 3:55 pm

getFullySelectedNode throws NullPointerException

Post by Denis »

Hi

we are using the Eclipse Oxygen Author in Version 15.2

I create a PropertyTester, which check if a node is fullySelected

Code: Select all

 AuthorNode fullySelectedNode = authorEditorPage.getFullySelectedNode();
.

Now I load a file with this content:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?><note nodeid="000001"><?graphic_path C:\Users\dzy\graphics/?><?tag ?><?rev A.1?><paragraph></paragraph></note>
The editor shows the content in the text-tab. When I jump to the author tab I get this exception:

Code: Select all

java.lang.NullPointerException
at ro.sync.exml.workspace.b.e.b.b.b.getSelectionStart(Unknown Source)
at ro.sync.exml.workspace.b.e.b.b.b.getFullySelectedNode(Unknown Source)
at ro.sync.ecss.extensions.g.getFullySelectedNode(Unknown Source)
at de.kgucms.kgu.tps.client.oxygen.integration.propertytester.EditorNodePropertyTester.test(EditorNodePropertyTester.java:47)
at org.eclipse.core.internal.expressions.Property.test(Property.java:58)
at org.eclipse.core.internal.expressions.TestExpression.evaluate(TestExpression.java:99)
at org.eclipse.core.internal.expressions.CompositeExpression.evaluateAnd(CompositeExpression.java:53)
at org.eclipse.core.internal.expressions.WithExpression.evaluate(WithExpression.java:72)
at org.eclipse.core.internal.expressions.ReferenceExpression.evaluate(ReferenceExpression.java:70)
at org.eclipse.core.internal.expressions.CompositeExpression.evaluateAnd(CompositeExpression.java:53)
at org.eclipse.core.internal.expressions.AndExpression.evaluate(AndExpression.java:29)
at org.eclipse.ui.internal.handlers.HandlerProxy.setEnabled(HandlerProxy.java:224)
at org.eclipse.core.commands.Command.setEnabled(Command.java:857)
at org.eclipse.ui.menus.CommandContributionItem.isEnabled(CommandContributionItem.java:968)
at org.eclipse.ui.menus.CommandContributionItem.updateToolItem(CommandContributionItem.java:661)
Best regards
Denis
Denis Zygann
KGU Consulting GmbH
http://www.kgu-consulting.com
Radu
Posts: 9472
Joined: Fri Jul 09, 2004 5:18 pm

Re: getFullySelectedNode throws NullPointerException

Post by Radu »

Hi Denis,

The method seems to be called very early, before the document was properly loaded in the Author editor mode.
If on the method "EditorNodePropertyTester.test" you catch and log this exception, does it occur every time or only when the document is opened?
So somehow you should avoid calling the API while the document is being opened and is thus not properly instantiated.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Denis
Posts: 47
Joined: Thu Jun 19, 2014 3:55 pm

Re: getFullySelectedNode throws NullPointerException

Post by Denis »

Hi

The exception occurs only, when I switch from the Text editor mode to the Author editor mode (I check if the page is an WSAuthorEditorPage). So you are right.

Is it possible to fix this NullPointerException and get null back, in the next version?

Best regards,
Denis
Denis Zygann
KGU Consulting GmbH
http://www.kgu-consulting.com
Radu
Posts: 9472
Joined: Fri Jul 09, 2004 5:18 pm

Re: getFullySelectedNode throws NullPointerException

Post by Radu »

Hi Denis,

I can do that but any API call would probably break with unexpected errors at this stage as the switch is not yet completed.
I do not know much about what you are doing, did you add a contribution item on the internal toolbar of the Author editor mode?
I'm not sure how you could check via the API if the page switch has fully finished.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Denis
Posts: 47
Joined: Thu Jun 19, 2014 3:55 pm

Re: getFullySelectedNode throws NullPointerException

Post by Denis »

Hi Radu,

you are right, I did add a contribution item to the internal toolbar. This item is only available, when a fullySelectedNode is selected. For that reason I add the property Tester.

Code: Select all


   if (currentPage instanceof WSAuthorEditorPage) {
WSAuthorEditorPage authorEditorPage = (WSAuthorEditorPage) currentPage;
try {
AuthorNode fullySelectedNode = authorEditorPage.getFullySelectedNode();
return fullySelectedNode != null;
} catch (NullPointerException e) {
return false;
}
}
In this case it is sufficient to return null. Instead of throwing a NullPointerException.

Best regards,
Denis
Denis Zygann
KGU Consulting GmbH
http://www.kgu-consulting.com
Post Reply