diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-code-oldcore/src/main/java/org/xwiki/rendering/internal/macro/code/source/AbstractEntityCodeMacroSourceFactory.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-code-oldcore/src/main/java/org/xwiki/rendering/internal/macro/code/source/AbstractEntityCodeMacroSourceFactory.java
index d0363b7d3a3200be77f9958150bcc105d7ed0827..2a81f8df47c63cf98ff65b3da6bc37b6dbbd49de 100644
--- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-code-oldcore/src/main/java/org/xwiki/rendering/internal/macro/code/source/AbstractEntityCodeMacroSourceFactory.java
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-code-oldcore/src/main/java/org/xwiki/rendering/internal/macro/code/source/AbstractEntityCodeMacroSourceFactory.java
@@ -86,7 +86,7 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans
             this.authorization.checkAccess(Right.VIEW, xcontext.getAuthorReference(), documentReference);
         } catch (AccessDeniedException e) {
             throw new MacroExecutionException(
-                "Current author is not allowed to access document [" + documentReference + "]");
+                "Current author is not allowed to access document [" + documentReference + "]", e);
         }
 
         // Current user must have view right on the document
@@ -98,9 +98,9 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans
         // Get the content
         XWikiDocument document;
         try {
-            document = xcontext.getWiki().getDocument(entityReference, xcontext);
+            document = xcontext.getWiki().getDocument(documentReference, xcontext);
         } catch (XWikiException e) {
-            throw new MacroExecutionException("Failed to load document [" + documentReference + "]");
+            throw new MacroExecutionException("Failed to load document [" + documentReference + "]", e);
         }
 
         // Get the current translation
@@ -109,7 +109,7 @@ public CodeMacroSource getContent(CodeMacroSourceReference reference, MacroTrans
                 document = document.getTranslatedDocument(xcontext);
             } catch (XWikiException e) {
                 throw new MacroExecutionException(
-                    "Failed to load document translation for reference [" + documentReference + "]");
+                    "Failed to load document translation for reference [" + documentReference + "]", e);
             }
         }
 
@@ -132,7 +132,7 @@ private CodeMacroSource getContent(XWikiDocument document, EntityReference entit
                 this.componentManager.getInstance(EntityCodeMacroSourceLoader.class, entityReference.getType().name());
         } catch (ComponentLookupException e) {
             throw new MacroExecutionException("Unexpected error when initializing the content loader for entity type ["
-                + entityReference.getType() + "]");
+                + entityReference.getType() + "]", e);
         }
 
         return loader.load(document, entityReference, reference, xcontext);
diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-code/src/main/java/org/xwiki/rendering/macro/code/source/CodeMacroSource.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-code/src/main/java/org/xwiki/rendering/macro/code/source/CodeMacroSource.java
index 2ae4b02a0350c933bb7ae072a8b096ce65f098e2..2d46e07a05dd648c08f031deafc55fdad6817202 100644
--- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-code/src/main/java/org/xwiki/rendering/macro/code/source/CodeMacroSource.java
+++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-code/src/main/java/org/xwiki/rendering/macro/code/source/CodeMacroSource.java
@@ -44,7 +44,7 @@ public class CodeMacroSource
     /**
      * @param reference the reference of the content
      * @param content the content to highlight
-     * @param language the language of the content
+     * @param language the language of the content if known, null otherwise
      */
     public CodeMacroSource(CodeMacroSourceReference reference, String content, String language)
     {
@@ -70,7 +70,7 @@ public String getContent()
     }
 
     /**
-     * @return the language of the content
+     * @return the language of the content if known, null otherwise
      */
     public String getLanguage()
     {