Details
-
Suggestion
-
Resolution: Won't Do
-
None
-
None
Description
NOTE: This suggestion is for JIRA Server. Using JIRA Cloud? See the corresponding suggestion.
Symptom
Attempting to view an attachment throws the following exception:
2012-11-20 14:26:32,775 http-8080-18 ERROR captain.planet 866x819921x1 9fma0l 127.0.0.1 /secure/attachment/23918/secret_plans.pdf [jira.web.servlet.ViewAttachmentServlet] Error serving file for path /23918/secret_plans.pdf: null java.lang.NullPointerException at java.util.regex.Matcher.getTextLength(Unknown Source) at java.util.regex.Matcher.reset(Unknown Source) at java.util.regex.Matcher.<init>(Unknown Source) at java.util.regex.Pattern.matcher(Unknown Source) at com.atlassian.gzipfilter.selector.PatternMatcher.matches(PatternMatcher.java:39) at com.atlassian.gzipfilter.selector.UrlRewriteGzipCompatibilitySelector.shouldGzip(UrlRewriteGzipCompatibilitySelector.java:31) at com.atlassian.gzipfilter.SelectingResponseWrapper.setContentType(SelectingResponseWrapper.java:55) at javax.servlet.ServletResponseWrapper.setContentType(ServletResponseWrapper.java:130) at javax.servlet.ServletResponseWrapper.setContentType(ServletResponseWrapper.java:130) at javax.servlet.ServletResponseWrapper.setContentType(ServletResponseWrapper.java:130)
Cause
Somehow it is possible that an uploaded file attachment will end up having an empty string as the mime type in the database (FILEATTACHMENT.MIMETYPE). Please see the picture:
Unfortunately, there are no steps to reproduce the problem. The suspect is that the problem happens when JIRA is under heavy load or concurrent modification of the same issue.
As a safeguard to avoid it happening again in the future, it can be made the following modification in JIRA's code, more specifically in the com.atlassian.jira.util.mime.MimeManager.java file:
public String getSanitisedMimeType(String existingMimeType, String fileName) { //only override the mime-type if it is a generic type /** * @SKYPE Also override mime-type when the browser does not send any mime-type for some reason as * this can cause not downloadable file attachments. * @DEV Priit Parmann */ if (existingMimeType == null || existingMimeType.equals("") || GENERIC_MIME_TYPES.contains(existingMimeType)) { return getSuggestedMimeType(fileName); } else { return existingMimeType; } }
It would be great if Atlassian would consider adding the same (or better) modification to the next release so that in the future there would be no attachments without mime types.
The case of empty mime type should also be handled when downloading the file.
Attachments
Issue Links
- relates to
-
JRACLOUD-22475 Prevent files from getting empty values for the "Mime Type" information
- Closed