Skip to content

Commit

Permalink
8244703: "platform encoding not initialized" exceptions with debugger…
Browse files Browse the repository at this point in the history
…, JNI

Reviewed-by: alanb, sspitsyn
  • Loading branch information
Alex Menkov committed May 28, 2020
1 parent 23ce03d commit f3c463b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
1 change: 0 additions & 1 deletion make/modules/jdk.jdwp.agent/Lib.gmk
Expand Up @@ -64,7 +64,6 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJDWP, \
LIBS_linux := $(LIBDL), \
LIBS_macosx := -liconv, \
LIBS_aix := -liconv, \
LIBS_windows := $(WIN_JAVA_LIB), \
))

$(BUILD_LIBJDWP): $(call FindLib, java.base, java)
Expand Down
6 changes: 3 additions & 3 deletions src/jdk.jdwp.agent/share/native/libjdwp/transport.c
Expand Up @@ -77,10 +77,10 @@ printLastError(jdwpTransportEnv *t, jdwpTransportError err)

/* Convert this string to UTF8 */
len = (int)strlen(msg);
maxlen = len+len/2+2; /* Should allow for plenty of room */
utf8msg = (jbyte*)jvmtiAllocate(maxlen+1);
maxlen = len * 4 + 1;
utf8msg = (jbyte*)jvmtiAllocate(maxlen);
if (utf8msg != NULL) {
(void)utf8FromPlatform(msg, len, utf8msg, maxlen+1);
(void)utf8FromPlatform(msg, len, utf8msg, maxlen);
}
}
if (rv == JDWPTRANSPORT_ERROR_NONE) {
Expand Down
28 changes: 21 additions & 7 deletions src/jdk.jdwp.agent/share/native/libjdwp/util.c
Expand Up @@ -26,6 +26,7 @@
#include <ctype.h>

#include "util.h"
#include "utf_util.h"
#include "transport.h"
#include "eventHandler.h"
#include "threadControl.h"
Expand Down Expand Up @@ -1652,13 +1653,26 @@ setAgentPropertyValue(JNIEnv *env, char *propertyName, char* propertyValue)
/* Create jstrings for property name and value */
nameString = JNI_FUNC_PTR(env,NewStringUTF)(env, propertyName);
if (nameString != NULL) {
valueString = JNU_NewStringPlatform(env, propertyValue);
if (valueString != NULL) {
/* invoke Properties.setProperty */
JNI_FUNC_PTR(env,CallObjectMethod)
(env, gdata->agent_properties,
gdata->setProperty,
nameString, valueString);
/* convert the value to UTF8 */
int len;
char *utf8value;
int utf8maxSize;

len = (int)strlen(propertyValue);
utf8maxSize = len * 4 + 1;
utf8value = (char *)jvmtiAllocate(utf8maxSize);
if (utf8value != NULL) {
utf8FromPlatform(propertyValue, len, (jbyte *)utf8value, utf8maxSize);
valueString = JNI_FUNC_PTR(env, NewStringUTF)(env, utf8value);
jvmtiDeallocate(utf8value);

if (valueString != NULL) {
/* invoke Properties.setProperty */
JNI_FUNC_PTR(env,CallObjectMethod)
(env, gdata->agent_properties,
gdata->setProperty,
nameString, valueString);
}
}
}
if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
Expand Down

0 comments on commit f3c463b

Please sign in to comment.