Analysis of XWIKI-24546
Symptom: An image uploaded inside an annotation (CKEditor in the annotation popup) is broken after save — only the filename shows. Plain comments and images from existing pages work fine.
Root cause — a broken assumption about cached-document mutation:
The annotation save flow (unchanged since XWIKI-18989, 2022) persists uploaded images like this:
1. AbstractAnnotationsRESTResource.postAnnotation → handleTemporaryUploadedFiles(docRef, metadata) (AbstractAnnotationRESTResource:417) does document = getWiki().getDocument(docRef) then attachTemporaryAttachmentsInDocument(document, uploadedFiles). It never saves this document.
2. attachTemporaryAttachmentsInDocument → document.setAttachment(...) → XWikiAttachmentList.updateList() → document.setMetaDataDirty(true) (XWikiAttachmentList.java).
3. annotationService.addAnnotation(...) → DefaultIOService.addAnnotation does its own getDocument(), document.clone(), adds the annotation xobject, and saves that instance (DefaultIOService.java:126,137,162).
Historically this worked purely by side effect: step 1's getDocument() returned the shared cached instance, setAttachment mutated it in place, and step 3's getDocument() returned that same mutated instance (so the clone carried the attachment).
The regression: XWIKI-22892 — "In loadXWikiDoc, automatically reload the cached document if it has been modified" (commit 6642dc59f50, first released in 17.2.0). It changed XWikiCacheStore.loadXWikiDoc to return the cached document only if !cachedoc.isMetaDataDirty() — otherwise it reloads a fresh copy from the
database. Because step 2 marks the cached doc dirty, step 3's getDocument() now reloads a clean DB copy without the attachment, clones that, and saves the annotation. The uploaded attachment is never persisted → broken image.
Version corroboration:
- XWIKI-22892 is in 17.2.0+ (verified via git tag --contains). The reported broken versions 17.10.9 and 18.4.1 contain it; the fix versions (17.10.10, 18.4.3, 18.6.0‑rc‑1 — no 16.10.x) match this exactly.
- On the 16.10.x branch loadXWikiDoc still returns the cached instance as-is (diff 16.10.10→16.10.18 for XWikiCacheStore.java is empty, isMetaDataDirty absent) — so per the code, 16.10.18 should not be affected. The "affects 16.10.18 / works on 16.10.10" note in the ticket is inconsistent with the code and worth
flagging to the reporter.
The same defect also affects the annotation edit path (SingleAnnotationRESTResource → updateAnnotations, same clone+save pattern).
The correct pattern is the one comments and normal edits use: attach the temporary files to the very document instance that gets saved (e.g. CommentAddAction attaches to doc then saves doc; XWikiDocument.readTemporaryUploadedFiles attaches to this).
Let me confirm the fix approach with you, since it's a design choice with backport implications.
Andreea Tarata Are you sure about the 16.10.18 affects version (did you try it)? I'm asking because my LLM said:
[...] so per the code, 16.10.18 should not be affected. The "affects 16.10.18 / works on 16.10.10" note in the ticket is inconsistent with the code and worth flagging to the reporter.
Thx
This message was sent by Atlassian Jira (v9.3.0#930000-sha1:287aeb6)
If image attachments aren't displayed, see this article.