Source:
<code>public URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, String xwikidb, XWikiContext context) { if ((context != null) && "viewrev".equals(context.getAction()) && context.get("rev") != null && isContextDoc(xwikidb, spaces, name, context)) { try { String docRevision = context.get("rev").toString(); XWikiAttachment attachment = findAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); if (attachment == null) { action = "viewattachrev"; } else { long arbId = findDeletedAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); return createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), arbId, querystring, xwikidb, context); } } catch (XWikiException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Exception while trying to get attachment version !", e); } } } if (isContextDoc(xwikidb, spaces, name, context)) { XWikiAttachment attachment = context.getDoc().getAttachment(filename); if (attachment != null) { return createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), querystring, xwikidb, context); } else { if (LOGGER.isErrorEnabled()) { LOGGER.error(String.format("Exception while trying to get attachment [%s] from [%s.%s]!", <START> filename, spaces, name)); <END> } } } return this.internalCreateAttachmentURL(filename, spaces, name, action, querystring, xwikidb, context); }</code><technical_language>practice: SLF4J syntax :) LOGGER.error("Exception while get attachment space [{}], page [{}]!", filename, spaces, name)); 2nd practice: separate variable []. Imagine case 1 (spaces ="Hello.World" name = "") case 2 (spaces="" name "Hello.World"), able differentiate debugging a production instance</technical_language>

Target:
public URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, String xwikidb, XWikiContext context) { XWikiAttachment attachment = null; URL attachmentURL = null; if ((context != null) && "viewrev".equals(context.getAction()) && context.get("rev") != null && isContextDoc(xwikidb, spaces, name, context)) { try { String docRevision = context.get("rev").toString(); attachment = findAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); if (attachment == null) { action = "viewattachrev"; } else { long arbId = findDeletedAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); attachmentURL = createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), arbId, querystring, xwikidb, context); } } catch (XWikiException e) { LOGGER.error("Failed to create attachment URL for filename in spaces [{}], page [{}], " + "action [{}], query string and wiki [{}]", filename, spaces, name, action, querystring, xwikidb, e); } } else if (isContextDoc(xwikidb, spaces, name, context)) { attachment = context.getDoc().getAttachment(filename); } else { WikiReference originalWikiReference = context.getWikiReference(); context.setWikiId(xwikidb); DocumentReference documentReference = new DocumentReference(xwikidb, spaces, name); try { XWikiDocument document = context.getWiki().getDocument(documentReference, context); attachment = document.getAttachment(filename); } catch (XWikiException e) { LOGGER.error("Exception while loading doc from wiki space and page [{}]", xwikidb, spaces, name, e); } finally { context.setWikiReference(originalWikiReference); } } if (attachmentURL == null && attachment != null) { attachmentURL = createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), querystring, xwikidb, context); } else if (attachmentURL == null){ attachmentURL = this.internalCreateAttachmentURL(filename, spaces, name, action, querystring, xwikidb, context); } return attachmentURL; }