Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-25748

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 14.10.2
    • Rendering - Code Macro
    • None
    • Unknown

    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).

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              vmassol Vincent Massol
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: