Troubleshooting
Problem
Java applications on Linux compiled using gcj (GNU Compiler for Java), which utilize the IBM Data Server Driver for JDBC and SQLJ (also known as JCC, Java Common Client), may fail with java.nio.charset.UnsupportedCharsetException, similar to the following:
Symptom
Exception in thread "main" java.nio.charset.UnsupportedCharsetException
at java.nio.charset.Charset.forName(libgcj.so.7rh)
at com.ibm.db2.jcc.am.t.<init>(t.java:13)
at com.ibm.db2.jcc.am.s.a(s.java:12)
at com.ibm.db2.jcc.am.o.a(o.java:428)
at com.ibm.db2.jcc.t4.cc.a(cc.java:2398)
at com.ibm.db2.jcc.t4.cb.a(cb.java:3407)
at com.ibm.db2.jcc.t4.cb.a(cb.java:1982)
at com.ibm.db2.jcc.t4.cb.a(cb.java:1913)
at com.ibm.db2.jcc.t4.cb.m(cb.java:749)
at com.ibm.db2.jcc.t4.cb.i(cb.java:252)
at com.ibm.db2.jcc.t4.cb.c(cb.java:54)
at com.ibm.db2.jcc.t4.q.c(q.java:44)
at com.ibm.db2.jcc.t4.rb.j(rb.java:147)
at com.ibm.db2.jcc.am.gn.ib(gn.java:2056)
at com.ibm.db2.jcc.am.gn.a(gn.java:3032)
at com.ibm.db2.jcc.am.gn.a(gn.java:667)
at com.ibm.db2.jcc.am.gn.executeQuery(gn.java:651)
at Db2Connect.main(Db2Connect.java:54)
Caused by: java.security.PrivilegedActionException:
java.lang.ClassNotFoundException: sun.io.ByteToCharConverter not found in
gnu.gcj.runtime.SystemClassLoader{...}
at java.security.AccessController.doPrivileged(libgcj.so.7rh)
Cause
The above exception will occur if the system class JAR file rt.jar is not explicitly referenced in the user environment variable CLASSPATH, or in the java executable invocation (in the '-classpath' argument). This JAR file contains the compiled class files for the base Java Runtime environment. It is normally located in
$JAVA_HOME/jre/lib
Where $JAVA_HOME is the locaction in which the Java Runtime is installed.
The root cause of this problem is that for performance reasons, the IBM Data Server Driver for JDBC and SQLJ calls the Sun I/O classes (sun.io.*) over the Java New I/O (java.nio.*) classes when possible. These classes are contained in rt.jar. Unless rt.jar is explicitly referenced in the runtime java class path, the GCJ runtime cannot load these classes.
Environment
This problem only occurs on Linux environments running the Free Software Foundation (FSF) Java Runtime Environment, and the GNU Compiler for Java (GCJ).
Diagnosing The Problem
Run
env | grep CLASSPATH
as the user that the application runs under, to confirm whether rt.jar is set in the user CLASSPATH environment variable.
Confirm that this jar file can be found in the expected location:
find $JAVA_HOME -name rt.jar
Resolving The Problem
Add this JAR to the CLASSPATH envivonment variable (e.g. in the user .profile).
Related Information
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21569499