Bug #14938 Unable to initialize character set mapping tables
Submitted: 15 Nov 2005 9:00 Modified: 15 Jan 2006 5:14
Reporter: Ai Hua
Status: No Feedback
Category:Connector/J Severity:S2 (Serious)
Version:3.1.11 OS:All OS
Assigned to: Target Version:

[15 Nov 2005 9:00] Ai Hua
Description:
I used is JAVA(J2SE 1.4.2) with the connectorJ/3.1 and mysql 4.1 database and SUN's J2EE
1.3.1 DK, Here is the Error i got: 

java.lang.ExceptionInInitializerError
at com.mysql.jdbc.Connection.<init>(Connection.java:1174)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:266)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at examples.first.SingleMA.run(singleMA.java:86)
at com.ibm.aglets.SystemMessage.handle(Unknown Source)
at com.ibm.aglets.AgletThread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Unable to initialize character set mapping tables
at com.mysql.jdbc.CharsetMapping.<clinit>(CharsetMapping.java:73)
... 7 more 

How to repeat:
Every time.

Suggested fix:
I think the code of line 69-70 in com.mysql.jdbc.CharsetMapping.java should be:

InputStream inStream = CharsetMapping.class
				.getResourceAsStream("/Charsets.properties");

instead of

InputStream inStream = CharsetMapping.class
				.getResourceAsStream("Charsets.properties");

As the SUN's Java API document say about Class.getResourceAsStream(String name):

This method delegates the call to its class loader, after making these changes to the
resource name: if the resource name starts with "/", it is unchanged; otherwise, the
package name is prepended to the resource name after converting "." to "/". If this object
was loaded by the bootstrap loader, the call is delegated to
ClassLoader.getSystemResourceAsStream.

So, in the J2EE context, the resource name should starts with "/". However, if the
Connector/J used in Application context, the resource(Charsets.properties)    
was loaded by the bootstrap loader, and it works well.

Regards.
[17 Nov 2005 21:42] Mark Matthews
Fixed for 3.1.12.
[14 Dec 2005 13:15] Pascal Alberty
Bug still present in 3.1.12

Debian 3.1 - JDK Sun 1.5 - Tomcat 5 - Apache 2
I had to take an old version 3.0.x to make it worked

Someone can confirm ?

Thanks
[14 Dec 2005 17:05] Mark Matthews
Can you come up with a testcase that duplicates this without having to duplicate your
entire environment?

(we run the JDBC compliance tests, which run in the J2EE RI, so it's not specific to the
J2EE RI from what I can tell).
[14 Dec 2005 17:16] Mark Matthews
Wrong state.
[15 Dec 2005 4:39] Animesh Singh
Well I have been using combination of Mysql driver 3.0.9, tomcat4.1.29 , jdk1.4.0 and
mysql4.0.12, for about two years without seeing any errors and exceptions. Now on other
machine we have mysql4.1.15 and jdk1.4.2, rest remains the same, we encounter following
problems.
1) If use 3.0.9 I am connected to database and can excercise add,uppdate delete,BUT at
times (roughly 2 occasion in every 10) see following

java.sql.SQLException: Communication link failure: java.io.IOException, underlying cause:
Unexpected end of input stream ** BEGIN NESTED EXCEPTION ** java.io.IOException MESSAGE:
Unexpected end of input stream STACKTRACE: java.io.IOException: Unexpected end of input
stream at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1405) 
2) In this new machine I earlier tried 3.1.11 but all the time it gave 

om.mysql.jdbc.Driver: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

3) Today I tried even 3.1.12, the problem is same as above.
We always keep Mysql driver in common/lib.

I hope that will be have some better insight. Looking for early resolution. For us to
think there seems some conflict of driver with the JDK version or Mysql4.1.15.
[15 Dec 2005 5:08] Mark Matthews
Without seeing your specific configuration, it's hard to say that it's an incompatibility,
especially since we run our entier testsuite on every check-in and before release using
JDK-1.4.2 on Linux, Solaris and Windows against MySQL-4.0, 4.1 and 5.0 (amongst other
combinations, but we definitely have coverage on the combination you're using).

A "ClassNotFoundException" on "com.mysql.jdbc.Driver" in my opinion points to a
configuration issue, not an incompatibility.
[15 Dec 2005 5:30] Mark Matthews
Pascal or Ai,

How _exactly_ do you have the driver deployed? Are there any other copies of it _anywhere_
in your classpath?

(We have folks running 3.1.11 and .12 in production on Tomcat as well we test it in that
environment, and using DBCP, so I know it works _generally_, so we need to figure out
what's specific to your two environments that causes it to fail).
[15 Dec 2005 7:40] Animesh Singh
Mark
Thanks, here are the variables and changed exception after two refershes.

1. We use poolman connection pooling,it has 

<minimumSize>0</minimumSize>
    <maximumSize>10</maximumSize>
    <connectionTimeout>1800</connectionTimeout>
	<userTimeout>12</userTimeout> 
	<skimmerFrequency>300</skimmerFrequency>    
    <shrinkBy>10</shrinkBy>
	<nativeResults>true</nativeResults>

    <debugging>true</debugging>

    <!-- Query Cache Attributes-->

    <cacheEnabled>true</cacheEnabled>
    <cacheSize>20</cacheSize>
    <cacheRefreshInterval>120</cacheRefreshInterval>

2. Mysql wait timeout =100

3. The exception as mentioned has changed to 

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying
exception: 

** BEGIN NESTED EXCEPTION ** 

java.io.EOFException

STACKTRACE:

java.io.EOFException
	at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1905)

worth mention will be the fact these confirguration remain same at two machines.
[15 Dec 2005 8:44] Pascal Alberty
Mark,

drivers used were 3.1.11 and 3.1.12.
Now, the working driver is 3.0.17-ga

I'll try to make a simple testcase to able you to reproduce.

Thanks
[15 Dec 2005 22:41] Rolf König
I'm using Windows 2000, JDK 1.5.0,Tomcat 5.5.9 and MySQL Version 4.1.13a-nt.

Connector/J 3.0.17-ga works fine, but not Connector/J 3.1.10:(java.lang.RuntimeException
in com.mysql.jdbc.CharsetMapping and
java.lang.ExceptionInInitializerError in com.mysql.jdbc.Connection)
[18 Dec 2005 13:32] Giedrius
Have the same poblem.

System config: Debian unstable (updated 2005 Dec 17), Java: 1.5.0_05-b05 (from sun),
Tomcat 5.0, MySQL: 4.1.15-Debian_1-log, and driver version is: 3.1.11. Most of the
configuration is left as provided by apt-get installation.

All the symptoms are as described here. I have tried to move jar file to ext directory of
jre, but that gave no results. Workaround that I have found is as follows:
1. Unjar archive into classes directory (I have unjared to my web application directory).
2. After this point exception changes to Access Denied.
3. Modify catalina.policy file. Add the folowing entry:
grant
{
    permission java.security.AllPermission;
};
It should be possible to allow only connect, listen and maybe some others, but I have not
expermented. However, granting permsissions to only ujared files failes to solve the
problem.

As far as I can say, it seems that this problem is specific to Debian. As all users that
has complained were using Debian system. However, I am not sure if it is true.

If some more information could help to solve the problem, please let me know. I will try
to do my best to provide it.
[16 Jan 2006 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[29 Jan 2006 19:27] Robert Hopek
We believe this particular issue is not at all related to characterset mappings and is
instead directly related to bug #8498.

We have just attempted to upgrade our servers from Connector/J v3.1.7 to v3.1.12 and
immediately threw an ExceptionInInitializerError; even on JSPs performing simplistic
queries. This is not on Debian but instead on Red Hat Enterprise 3. We are running MySQL
v4.1.14, JDK 1.5.0_02, Tomcat 5.5.9 and the aforementioned connector.

The code of the simple JSP is as follows:

<pre>
<%@ page contentType = "text/html;charset = Big5" import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>JDBC Test</TITLE>
</HEAD>
<BODY>
<CENTER>
<FONT SIZE = 5 COLOR = red>JDBC Test</FONT>
</CENTER>
<HR>
<P></P>
<CENTER>
<%
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/database","username",
"password");
  Statement stmt = con.createStatement();
  ResultSet rs = stmt.executeQuery("select field1, field2 from test");
%>
<TABLE bgcolor=DodgerBlue>
<TR bgcolor=SkyBlue>
<TD><B>Field 1</B></TD><TD><B>Field 2</B></TD>
</TR>
<%
   while (rs.next())
   {
        %>
<TR bgcolor=yellow>
<TD><%= rs.getString("field1") %></TD>
<TD><%= rs.getInt("field2") %></TD>
</TR>
<%
   }
    con.close();
    stmt.close();
    rs.close();
   %>
</TABLE>
</CENTER>
</BODY>
</HTML>
</pre>

We do use Security Manager; however, the entire /common directory of Tomcat has
AllPermissions set and port 3306 has the relevant SocketPermission set (the driver is
deployed into /common/lib and has been for years [since v2 mmsql days]). Under Connector/J
v3.1.7, we get the expected table output with the relevant values. Under Connector/J
v3.1.12, we instead throw the following exception:

----------------
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling
this request.

exception

javax.servlet.ServletException
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)

	org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:65)
	org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:768)
	java.security.AccessController.doPrivileged(Native Method)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:766)
	org.apache.jsp.jdbctest_jsp._jspService(org.apache.jsp.jdbctest_jsp:97)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:585)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)

root cause

java.lang.ExceptionInInitializerError
	com.mysql.jdbc.Connection.<init>(Connection.java:1175)
	com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	java.sql.DriverManager.getConnection(DriverManager.java:525)
	java.sql.DriverManager.getConnection(DriverManager.java:171)
	org.apache.jsp.jdbctest_jsp._jspService(org.apache.jsp.jdbctest_jsp:58)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:585)
	org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243)
	java.security.AccessController.doPrivileged(Native Method)
	javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)
----------------
[30 Jan 2006 18:30] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/1880
[30 Jan 2006 18:31] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/1881
[30 Jan 2006 18:32] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/1882
[30 Jan 2006 18:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/1884
[27 Apr 2006 19:52] joerg maier
For me this bug is still present in mysql-connector-java-3.1.12-bin.jar, even if i read
Fixed BUG#14938 - Unable to initialize character set mapping". 

I run debian etch x86, sun hotspot jdk 1.4.2_11-b06, mixed mode, tomcat 5.0.30-9.

When trying to initialize a jdbc connection from the jar in ${catalina.home}/shared/lib i
get:
2006-04-27 19:48:38 StandardWrapperValve[TestJdbcServlet]: Servlet.service() for servlet
TestJdbcServlet threw exception
java.lang.ExceptionInInitializerError
        at com.mysql.jdbc.Connection.<init>(Connection.java:1175)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
        at java.sql.DriverManager.getConnection(DriverManager.java:171)
        at mypackage.TestJdbc.doGet(TestJdbc.java:56)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
        at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:272)
        at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.ja
va:245)
        at
org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationFilterChain.java:177)
        at
org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:156)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:152)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198
)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Pr
otocol.java:705)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
        at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.RuntimeException: Unable to initialize character set mapping tables
        at com.mysql.jdbc.CharsetMapping.<clinit>(CharsetMapping.java:73)
        ... 43 more

Loading the mysql jdbc classes from application lib path works perfectly.

Regards, Joerg
[5 May 2006 2:55] Keshava Berg
As stated above this bug is still present in the 3.1.12 version of the connector. However
Mark Mathews submitted a change in http://lists.mysql.com/commits/1884. If you copy the
setProperty mappings from his checkin log to your source copy of the CharsetMapping.java
and rebuild the connector jar using the build.xml and use the newly built jar it works
just fine. 

Thanks Mark but are there plans for a 3.1.13 version of the connector that will include
this change?