STRCAT in C code crashing JVM, debug/logging how-to help needed
Hi Guys
I'm very inexperienced in debugging JNI/native lib, helps are very much appreicated. I've written C code to use a native library (.so) and also generate Java exception using the code below when making native method call via JNI, everything was running ok.
However, I sometimes get problem at STRCAT method in throwExceptionWithConvDump ( see below) and I don't how to debug such thing, and also I can not reproduce this exception as most of the time everything works perfectly normal. Please help me out if you know C code and tell me what have I done wrong or what should I do to make my useage of STRCAT more error proof. Or if you know how should I debug this issue. Thank you verymuch for helping.
Env:
Java 1.5
Tomcat 5
Log4J
Note: The XXX is the package that I don't have source code.
*
* Throwing a Java Exception
*
*/
void throwJavaException(JNIEnv *env,char *errorMsg,char *errorClass)
{
jclass newExcCls;
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
newExcCls = (*env)->FindClass(env, errorClass);
if (newExcCls == NULL)
newExcCls = (*env)->FindClass(env,"com/XXX/CAPIException");
if (newExcCls == NULL){
printf("in throwJavaException() : can't find com/XXX/CAPIException");
return;
}else{
printf("found com/XXX/CAPIException!! ");
}
(*env)->ThrowNew(env, newExcCls, errorMsg);
}
/*
* Throwing a Java Exception with error code and conversation dump
*
*/
void throwExceptionWithConvDump(JNIEnv *env, XXXErr XXX_err,char *convDump,char *errorClass)
{
char errNum[2];
sprintf(errNum,"%i", (int)cai_err);
char *errorMsg;
STRCPY(errorMsg,"\n XXX APIV Error: ErrorCode = $");
STRCAT(errorMsg,errNum);
STRCAT(errorMsg,"$ ");
STRCAT(errorMsg,XXX_getErrorStr(cai_err) );
STRCAT(errorMsg,"\n Conversation Dump : \n\n" );
STRCAT(errorMsg, convDump );
throwJavaException(env, errorMsg, errorClass);
}
Error :
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (0xb) at pc=0xb75118b3, pid=31052, tid=2617514928
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_09-b01 mixed mode)
# Problematic frame:
# C [libc.so.6+0x768b3] strcat+0x53
#
T H R E A D
...
...
Stack: [0x9bfc1000,0x9c042000), sp=0x9c041220, free space=512k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libc.so.6+0x768b3] strcat+0x53
C [libAmadeusProxy.so+0x904cf4] Java_com_XXX_sendXmlQuery+0xda
...
...
..
..
v ~OSRAdapter
v ~StubRoutines::call_stub
V [libjvm.so+0x17a75c]
V [libjvm.so+0x28afd8]
V [libjvm.so+0x179fb5]
V [libjvm.so+0x17a04e]
V [libjvm.so+0x1f1785]
V [libjvm.so+0x2f43d3]
V [libjvm.so+0x28bbe8]
C [libpthread.so.0+0x4dac]

