--- old/src/java.base/windows/native/libjava/ProcessHandleImpl_win.c 2020-03-27 17:42:56.000000000 +0900 +++ new/src/java.base/windows/native/libjava/ProcessHandleImpl_win.c 2020-03-27 17:42:55.000000000 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -469,16 +469,28 @@ } static void getCmdlineInfo(JNIEnv *env, HANDLE handle, jobject jinfo) { - char exeName[1024]; - int bufsize = sizeof exeName; - jstring commandObj; - - if (QueryFullProcessImageName(handle, 0, exeName, &bufsize)) { - commandObj = (*env)->NewStringUTF(env, exeName); - CHECK_NULL(commandObj); - (*env)->SetObjectField(env, jinfo, - ProcessHandleImpl_Info_commandID, commandObj); + WCHAR exeName[1024]; + WCHAR *longPath; + DWORD bufsize = sizeof(exeName)/sizeof(WCHAR); + jstring commandObj = NULL; + + if (QueryFullProcessImageNameW(handle, 0, exeName, &bufsize)) { + commandObj = (*env)->NewString(env, (const jchar *)exeName, + (jsize)wcslen(exeName)); + } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + bufsize = 32768; + longPath = (WCHAR*)malloc(bufsize * sizeof(WCHAR)); + if (longPath != NULL) { + if (QueryFullProcessImageNameW(handle, 0, longPath, &bufsize)) { + commandObj = (*env)->NewString(env, (const jchar *)longPath, + (jsize)wcslen(longPath)); + } + free(longPath); + } } + CHECK_NULL(commandObj); + (*env)->SetObjectField(env, jinfo, + ProcessHandleImpl_Info_commandID, commandObj); } static void procToUser(JNIEnv *env, HANDLE handle, jobject jinfo) {