This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-c36759d8-efbf-4c8f-a367-4a0e575f4865 XWIKI-25748 Open

The page_object_property source type of the code macro always fails with a NullPointerException

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-3252dfef-8601-4994-96f2-43c3c42bc326 Vincent Massol created this issue on 12/Nov/26 20:28
 
Summary: The page_object_property source type of the code macro always fails with a NullPointerException
Issue Type: cid:jira-generated-image-avatar-c36759d8-efbf-4c8f-a367-4a0e575f4865 Bug
Affects Versions: 14.10.2
Assignee: Unassigned
Components: Rendering - Code Macro
Created: 12/Nov/26 20:28
Priority: cid:jira-generated-image-static-major-1f400a92-f2ae-418d-aa92-8321d7ed3895 Major
Reporter: Vincent Massol
Description:

The page_object_property source type of the code macro never works: the macro always fails with a NullPointerException instead of displaying the property, whatever the reference. The object_property type, which points to the same property with a document reference, works.

Steps to reproduce

  1. Create a page Sandbox.MyPage holding a XWiki.StyleSheetExtension object with some CSS in its code property.
  2. On another page, add:
    {{code source="object_property:Sandbox.MyPage^XWiki.StyleSheetExtension.code"}}{{/code}}
    
    {{code source="page_object_property:Sandbox/MyPage/XWiki.StyleSheetExtension[0]/code"}}{{/code}}
    
  3. View the page.

Expected: both macros display the CSS of the object.
Actual: the first one does; the second one displays "Failed to execute the [code] macro. Cause: [Cannot invoke "com.xpn.xwiki.objects.BaseObject.get(String)" because "xobject" is null]".

java.lang.NullPointerException: Cannot invoke "com.xpn.xwiki.objects.BaseObject.get(String)" because "xobject" is null
  at org.xwiki.rendering.internal.macro.code.source.DocumentObjectPropertyCodeMacroSourceLoader.load(DocumentObjectPropertyCodeMacroSourceLoader.java:57)
  at org.xwiki.rendering.internal.macro.code.source.AbstractEntityCodeMacroSourceFactory.getContent(AbstractEntityCodeMacroSourceFactory.java:143)
  at org.xwiki.rendering.internal.macro.code.source.AbstractEntityCodeMacroSourceFactory.getContent(AbstractEntityCodeMacroSourceFactory.java:121)
  at org.xwiki.rendering.internal.macro.code.source.DefaultCodeMacroSourceFactory.getContent(DefaultCodeMacroSourceFactory.java:69)
  at org.xwiki.rendering.internal.macro.code.CodeMacro.getContent(CodeMacro.java:131)

Cause

DocumentObjectPropertyCodeMacroSourceLoader handles both OBJECT_PROPERTY and PAGE_OBJECT_PROPERTY, and gets the object with XWikiDocument.getXObject(entityReference.getParent()). For a page reference, that parent is a PAGE_OBJECT reference, which getXObject(EntityReference) doesn't support (it handles DOCUMENT and OBJECT only) and answers with null. The loader doesn't check for null, so an object_property reference to an object that doesn't exist fails with the same exception instead of an "Unknown object" error.

Reproduced on 18.9.0. The code is unchanged since the source parameter was introduced (XWIKI-20462, 14.10.2).