java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters when using national characters java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters when using national characters linux linux

java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters when using national characters


just set environment variables "LANG=en_US.UTF-8" or some other "xxx.UTF-8".(https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html)

JNIEXPORT jboolean JNICALLJava_java_io_UnixFileSystem_createDirectory(JNIEnv *env, jobject this,                                            jobject file){    jboolean rv = JNI_FALSE;     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {        if (mkdir(path, 0777) == 0) {            rv = JNI_TRUE;        }    } END_PLATFORM_STRING(env, path);    return rv;}
#define WITH_PLATFORM_STRING(env, strexp, var)                                    if (1) {                                                                          const char *var;                                                              jstring _##var##str = (strexp);                                               if (_##var##str == NULL) {                                                        JNU_ThrowNullPointerException((env), NULL);                                   goto _##var##end;                                                        }                                                                             var = JNU_GetStringPlatformChars((env), _##var##str, NULL);                   if (var == NULL) goto _##var##end; #define WITH_FIELD_PLATFORM_STRING(env, object, id, var)                          WITH_PLATFORM_STRING(env,                                                                          ((object == NULL)                                                              ? NULL                                                                        : (*(env))->GetObjectField((env), (object), (id))),                          var)
  1. Java natively translates all string to platform's local encoding in this method: jdk/src/share/native/common/jni_util.c - JNU_GetStringPlatformChars() . System property sun.jnu.encoding is used to determine the platform's encoding.

  2. The value of sun.jnu.encoding is set at jdk/src/solaris/native/java/lang/java_props_md.c - GetJavaProperties() using setlocale() method of libc. Environment variable LC_ALL is used to set the value of sun.jnu.encoding. Value given at the command prompt using -Dsun.jnu.encoding option to Java is ignored.

(from https://stackoverrun.com/cn/q/3020937)


If the national characters are hardcoded in your source, convert the source file to the same encoding. You can use vim:

vim SourceClassWithHardcodedCharacters.java:set fileencoding=utf-8<Enter>:w<Enter>

If there is an issue, you will get a message ("unmappable character (...)").

For me, the issue is related either with 1. hardcoding characters in incorrect encoding or 2. losing the encoding somehow during passing the path to the method.