--- old/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp 2018-12-11 11:28:29.201122000 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp 2018-12-11 11:28:27.937118300 +0530 @@ -249,7 +249,8 @@ if (clazz == NULL) { return NULL; } - jobjectArray nameArray; + jobjectArray nameArray = NULL; + jobjectArray emptyArray = env->NewObjectArray(1, clazz, NULL); try { ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, @@ -270,13 +271,14 @@ } } - // Allocate space only for the network type printers - nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL); - if (nameArray == NULL) { - throw std::bad_alloc(); + // return remote printers only if the list contains it. + if (remotePrintersCount > 0) { + // Allocate space only for the network type printers + nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL); + if (nameArray == NULL) { + throw std::bad_alloc(); + } } - } else { - nameArray = NULL; } // Loop thro' network printers list only @@ -298,7 +300,12 @@ delete [] pPrinterEnum; delete [] pNetworkPrinterLoc; - return nameArray; + + if (nameArray != NULL) { + return nameArray; + } else { + return emptyArray; + } CATCH_BAD_ALLOC_RET(NULL); }