Uploaded image for project: 'Confluence Cloud'
  1. Confluence Cloud
  2. CONFCLOUD-60258

Insert macro in classic editor with custom editor dialog: saveMacro without body causes NPE

    XMLWordPrintable

Details

    Description

      See Connect doc:

      The doc says about macroBody of saveMacro:
      "the macro body to be saved with the macro. If omitted, the existing body will remain untouched."

      My macro has a custom editor dialog. When I insert my macro, the dialog is displayed.

      In the dialog close handler, I set macro params without body like this:
      confluence.saveMacro(macroParams);

      There will be NPE:
      user-activity-xhr-header.js:54
      POST http://localhost:8080/wiki/rest/tinymce/1/macro/placeholder 500 (Internal Server Error)

      Stacktrace:

      java.lang.NullPointerException: Missing storage body
      	at java.util.Objects.requireNonNull(Objects.java:228)
      	at com.atlassian.confluence.content.render.xhtml.definition.RichTextMacroBody.withStorage(RichTextMacroBody.java:18)
      	at com.atlassian.confluence.tinymceplugin.rest.MacroResource.getMacroBody(MacroResource.java:157)
      	at com.atlassian.confluence.tinymceplugin.rest.MacroResource.generatePlaceHolder(MacroResource.java:134)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      

       

      Workaround

      You need to call saveMacro({}, body) with a body value. If the macro has a body, you will need to pre-fetch it with getMacroBody().

      Attachments

        Activity

          People

            Unassigned Unassigned
            ndao Ngoc Dao
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: