--- old/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java 2018-12-03 21:16:23.652098200 +0530 +++ new/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java 2018-12-03 21:16:22.610451000 +0530 @@ -403,13 +403,19 @@ list. */ class RemotePrinterChangeListener implements Runnable { - private String[] prevRemotePrinters; + private String[] prevRemotePrinters = null; RemotePrinterChangeListener() { prevRemotePrinters = getRemotePrintersNames(); } boolean doCompare(String[] str1, String[] str2) { + if (str1 == null && str2 == null) { + return false; + } else if ((str1 == null && str2 != null) || (str2 == null && str1 != null)) { + return true; + } + if (str1.length != str2.length) { return true; } else { @@ -428,15 +434,19 @@ @Override public void run() { while (true) { - String[] currentRemotePrinters = getRemotePrintersNames(); - if (doCompare(prevRemotePrinters, currentRemotePrinters)) { + if (prevRemotePrinters != null) { + String[] currentRemotePrinters = getRemotePrintersNames(); + if (doCompare(prevRemotePrinters, currentRemotePrinters)) { + + // updated the printers data + // printers list now contains both local and network printer data + refreshServices(); - // updated the printers data - // printers list now contains both local and network printer data - refreshServices(); - - // store the current data for next comparison - prevRemotePrinters = currentRemotePrinters; + // store the current data for next comparison + prevRemotePrinters = currentRemotePrinters; + } + } else { + prevRemotePrinters = getRemotePrintersNames(); } try { --- old/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp 2018-12-03 21:16:29.499830100 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp 2018-12-03 21:16:28.500700300 +0530 @@ -270,10 +270,15 @@ } } - // 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; } } else { nameArray = NULL; --- old/test/jdk/java/awt/print/RemotePrinterStatusRefresh/RemotePrinterStatusRefresh.java 2018-12-03 21:16:35.242438800 +0530 +++ new/test/jdk/java/awt/print/RemotePrinterStatusRefresh/RemotePrinterStatusRefresh.java 2018-12-03 21:16:34.226475700 +0530 @@ -23,7 +23,7 @@ /** * @test - * @bug 8153732 + * @bug 8153732 8212202 * @requires (os.family == "Windows") * @summary Windows remote printer changes do not reflect in lookupPrintServices() * @ignore Requires a new network printer installation\removal