Bug #37931 Null Pointer Exception Thrown When specifying invalid character_set_results enc.
Submitted: 7 Jul 2008 14:55 Modified: 25 May 2012 20:30
Reporter: Jürgen Hötzel Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.6 OS:Any
Assigned to: CPU Architecture:Any

[7 Jul 2008 14:55] Jürgen Hötzel
Description:
Null-Pointer Exception is thrown, because the return value from 

CharsetMapping.getMysqlEncodingForJavaEncoding(charsetResults	.toUpperCase(Locale.ENGLISH), this)

is not checked (like in the "SET names" part for the characterEncoding property).

How to repeat:
Use the following JDBC_URI:

jdbc:mysql://localhost/test?characterEncoding=ISO8859-1&characterSetResults=ISO8859-1"

"-" is used instead of "_" 

Suggested fix:
--- ConnectionImpl.java.sic     2008-07-07 16:50:49.000000000 +0200
+++ ConnectionImpl.java 2008-07-07 16:26:19.000000000 +0200
@@ -1812,7 +1812,8 @@
                                        // Only change the value if needed
                                        //
 
-                                       if (!mysqlEncodingName.equalsIgnoreCase(
+                                       if ((mysqlEncodingName != null) && 
+                                           !mysqlEncodingName.equalsIgnoreCase(
                                                        (String)this.serverVariables.get("character_set_results"))) {
                                                StringBuffer setBuf = new StringBuffer(
                                                                "SET character_set_results = ".length()
[17 Jul 2008 11:30] Tonci Grgin
Hi Jürgen and thanks for your report. Verified just as described on latest c/J 5.1 sources.
[25 May 2012 20:30] John Russell
Added to changelog for 5.1.21: 

Specifying a non-existent character set in the characterEncoding or
characterSetResults connection options could produce a
NullPointerException error. The error could occur with a
typographical mistake, such as using a hyphen instead of an
underscore in the name.