Details
-
Bug
-
Resolution: Duplicate
-
Major
-
None
-
3.1
-
None
-
Unknown
-
Description
public void loadAttachmentContent(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException { try { if (bTransaction) { checkHibernate(context); bTransaction = beginTransaction(false, context); } Session session = getSession(context); String db = context.getDatabase(); String attachdb = (attachment.getDoc() == null) ? null : attachment.getDoc().getDatabase(); try { if (attachdb != null) { context.setDatabase(attachdb); } // Hibernate calls setContent which causes isContentDirty to be true. This is not what we want. content.setContentDirty(false); } finally { context.setDatabase(db); } if (bTransaction) { endTransaction(context, false, false); } } catch (Exception e) { Object[] args = {attachment.getFilename(), attachment.getDoc().getFullName()}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT, "Exception while loading attachment {0} of document {1}", e, args); } finally { try { if (bTransaction) { endTransaction(context, false, false); } } catch (Exception e) { } } }
The following 3 lines
XWikiAttachmentContent content = new XWikiAttachmentContent(attachment); attachment.setAttachment_content(content); session.load(content, new Long(content.getId()));
Show that if session.load fails, then still the attachment content is set in the attachment object, thus leading to a corrupt cache of the attachment content.
The lines should be inverted or failure should be caught to unset the attachment content.
This issue was experience on a production server (attachment being corrupt although the data correct in the DB. Flush cache fixed the issue)
Attachments
Issue Links
- duplicates
-
XWIKI-6848 Sometimes downloaded attachments are empty
- Closed