java.lang.NullPointerException while uploading/downloading attachments with non-latin characters
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
When the end user is trying to upload the attachment with unicode non-latin characters in the file name Confluence throw Internal Server Error because of the NullPointerException
The following appears in the atlassian-confluence.log
2017-01-25 17:28:59,563 ERROR [http-nio-8090-exec-5] [atlassian.confluence.servlet.ConfluenceServletDispatcher] sendError Could not execute action
-- url: /pages/doattachfile.action | traceId: 9fca5b65981e2fab | userName: username | referer: http://confluence.com:8090/pages/viewpageattachments.action?pageId=9535506
java.lang.NullPointerException
at com.atlassian.confluence.pages.actions.beans.AttachmentStorer.attachFiles(AttachmentStorer.java:57)
at com.atlassian.confluence.pages.actions.AbstractViewAttachmentsAction.execute(AbstractViewAttachmentsAction.java:98)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:168)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
at com.atlassian.confluence.core.ConfluenceWorkflowInterceptor.intercept(ConfluenceWorkflowInterceptor.java:33)
....
Diagnosis
Environment
- You have Confluence installed with PostgreSQL database
Diagnostic Steps
- Check Encoding, Collation and CType of the database used by Confluence
- The correct values should be:
- Encoding: UTF8
- Collation: en_US.UTF-8 (or any other ISO 15897 compatible unicode locale i.e. cs_CZ.UTF-8 for Czech and de_CH.UTF-8 for Swiss German)
- CType: en_US.UTF-8 (or any other ISO 15897 compatible unicode locale i.e. cs_CZ.UTF-8 for Czech and de_CH.UTF-8 for Swiss German)
- If you have different values for the mentioned parameters - your database is not configured correctly.
Cause
According to Configuring Database Character Encoding:
If LC_CTYPE is set to either "C" or "POSIX" then certain string functions such as converting to and from upper and lower case will not work correctly with international characters. Correct settings for this value take the form <LOCALE>.<ENCODING> (en_AU.UTF8 for example).
Resolution
In case of PostgreSQL there is no solution which can allow you changing the collation and CType of the database with the data. Check in with the following documentation: How to fix the collation of a Postgres Confluence database
The only solution is to create new database with the correct Collation and CType and migrate the data with Pg_dump
Please follow PostgreSQL documentation in order to create the database with correct collation and CType: PostgreSQL: Chapter 22. Localization