Bug #67828 Crashing applets due to reading file.encoding system property
Submitted: 6 Dec 2012 17:38 Modified: 26 Sep 22:51
Reporter: Pavel Drášil Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.22 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[6 Dec 2012 17:38] Pavel Drášil
Description:
Since version 5.1.17, the com.mysql.jdbc.StringUtils class reads system property "file.encoding" in its static initialization. This makes using Connector/J in Applets very problematic, because by default Applets do not have the right to read this property. As a result, Applets using Connector/J crash severely due to the ExceptionInInitializerError.

How to repeat:
Connect to MySQL from any Applet running on Oracle JRE with unchanged java.policy file.
[6 Dec 2012 18:01] Sveta Smirnova
Thank you for the report.

Please provide small test case, demonstrating the problem.
[6 Dec 2012 19:26] Pavel Drášil
Bug demonstration

Attachment: TestCase.zip (application/x-zip-compressed, text), 780.02 KiB.

[6 Dec 2012 19:43] Sveta Smirnova
Thank you for the feedback.

Verified as described.
[26 Sep 22:51] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 8.0.31 changelog: 

"Using Connector/J in a Java applet caused an ExceptionInInitializerError and made the applet quit unexpectedly. This was because the com.mysql.jdbc.StringUtils class tried to read the system property file.encoding, which is in accessible by the java.applet.Applet class. With this fix, Connector/J avoids the error by using Charset.defaultCharset() instead to get the information it needs."
[30 Sep 15:04] Daniel So
Posted by developer:
 
Updated the changelog entry to the following: 

"Due to some old limitations, when used with Java applets, Connector/J found out the default character set on a system by various workarounds like reading the system property file.encoding, using an OutpuStreamWriter, etc. With this fix, Connector/J now uses Charset.defaultCharset(), the standard method for the purpose."