Skip to content

Commit

Permalink
Improve error message on duplicate class definition
Browse files Browse the repository at this point in the history
1. Add an error message on LinkageError when a duplicate class 
definition is found.
2. Change setCurrentExceptionNLSWithArgs() to pass in NULL rather 
than an empty string as the default message.
j9nls_lookup_message() directly returns the default message when it 
is not NULL and the locale is English, making the message in
setCurrentExceptionNLSWithArgs() always to be the default empty string.

Fixes #11243

Signed-off-by: Hang Shao <hangshao@ca.ibm.com>
  • Loading branch information
hangshao0 committed Nov 25, 2020
1 parent 3f38e9b commit bb47342
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion runtime/j9vm/j7vmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,7 @@ jvmDefineClassHelper(JNIEnv *env, jobject classLoaderObject,
if (vmFuncs->hashClassTableAt(classLoader, utf8Name, utf8Length) != NULL) {
/* Bad, we have already defined this class - fail */
threadEnv->monitor_exit(vm->classTableMutex);
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGLINKAGEERROR, (UDATA *)*(j9object_t*)className);
vmFuncs->setCurrentExceptionNLSWithArgs(currentThread, J9NLS_JCL_DUPLICATE_CLASS_DEFINITION, J9VMCONSTANTPOOL_JAVALANGLINKAGEERROR, utf8Length, utf8Name);
goto done;
}

Expand Down
5 changes: 2 additions & 3 deletions runtime/jcl/common/jcldefine.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#include "j9consts.h"
#include "jclprots.h"
#include "j9protos.h"


#include "j9jclnls.h"

jclass
defineClassCommon(JNIEnv *env, jobject classLoaderObject,
Expand Down Expand Up @@ -144,7 +143,7 @@ defineClassCommon(JNIEnv *env, jobject classLoaderObject,
/* Bad, we have already defined this class - fail */
omrthread_monitor_exit(vm->classTableMutex);
if (J9_ARE_NO_BITS_SET(*options, J9_FINDCLASS_FLAG_NAME_IS_INVALID)) {
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGLINKAGEERROR, (UDATA *)*(j9object_t*)className);
vmFuncs->setCurrentExceptionNLSWithArgs(currentThread, J9NLS_JCL_DUPLICATE_CLASS_DEFINITION, J9VMCONSTANTPOOL_JAVALANGLINKAGEERROR, utf8Length, utf8Name);
}
goto done;
}
Expand Down
8 changes: 8 additions & 0 deletions runtime/nls/j9cl/j9jcl.nls
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,11 @@ J9NLS_JCL_NEST_MEMBER_CLAIMS_DIFFERENT_NEST_HOST.system_action=The JVM will thro
J9NLS_JCL_NEST_MEMBER_CLAIMS_DIFFERENT_NEST_HOST.user_response=Contact the provider of the classfile for a corrected version.
# END NON-TRANSLATABLE

J9NLS_JCL_DUPLICATE_CLASS_DEFINITION=A duplicate class definition for %2$.*1$s is found
# START NON-TRANSLATABLE
J9NLS_JCL_DUPLICATE_CLASS_DEFINITION.sample_input_1=3
J9NLS_JCL_DUPLICATE_CLASS_DEFINITION.sample_input_2=Foo
J9NLS_JCL_DUPLICATE_CLASS_DEFINITION.explanation=A duplicated class definition is found.
J9NLS_JCL_DUPLICATE_CLASS_DEFINITION.system_action=The JVM will throw a LinkageError.
J9NLS_JCL_DUPLICATE_CLASS_DEFINITION.user_response=Ensure there is no duplicate definition for the class in the message and try again.
# END NON-TRANSLATABLE
2 changes: 1 addition & 1 deletion runtime/vm/exceptionsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ setCurrentExceptionNLSWithArgs(J9VMThread * vmThread, U_32 nlsModule, U_32 nlsID
nlsMsgFormat = omrnls_lookup_message(J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE,
nlsModule,
nlsID,
"");
NULL);

va_start(stringArgList, exceptionIndex);
msgCharLength = j9str_vprintf(NULL, 0, nlsMsgFormat, stringArgList);
Expand Down

0 comments on commit bb47342

Please sign in to comment.