mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8212202: [Windows] Exception if no printers are installed
Reviewed-by: prr
This commit is contained in:
parent
c373740319
commit
d644970c02
3 changed files with 45 additions and 17 deletions
|
@ -403,18 +403,36 @@ public class PrintServiceLookupProvider extends PrintServiceLookup {
|
||||||
list.
|
list.
|
||||||
*/
|
*/
|
||||||
class RemotePrinterChangeListener implements Runnable {
|
class RemotePrinterChangeListener implements Runnable {
|
||||||
private String[] prevRemotePrinters;
|
private String[] prevRemotePrinters = null;
|
||||||
|
|
||||||
RemotePrinterChangeListener() {
|
RemotePrinterChangeListener() {
|
||||||
prevRemotePrinters = getRemotePrintersNames();
|
prevRemotePrinters = getRemotePrintersNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean doCompare(String[] str1, String[] str2) {
|
boolean doCompare(String[] str1, String[] str2) {
|
||||||
|
if (str1 == null && str2 == null) {
|
||||||
|
return false;
|
||||||
|
} else if (str1 == null || str2 == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (str1.length != str2.length) {
|
if (str1.length != str2.length) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0;i < str1.length;i++) {
|
for (int i = 0;i < str1.length;i++) {
|
||||||
for (int j = 0;j < str2.length;j++) {
|
for (int j = 0;j < str2.length;j++) {
|
||||||
|
// skip if both are nulls
|
||||||
|
if (str1[i] == null && str2[j] == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return true if there is a 'difference' but
|
||||||
|
// no need to access the individual string
|
||||||
|
if (str1[i] == null || str2[j] == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do comparison only if they are non-nulls
|
||||||
if (!str1[i].equals(str2[j])) {
|
if (!str1[i].equals(str2[j])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -428,15 +446,19 @@ public class PrintServiceLookupProvider extends PrintServiceLookup {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
String[] currentRemotePrinters = getRemotePrintersNames();
|
if (prevRemotePrinters != null && prevRemotePrinters.length > 0) {
|
||||||
if (doCompare(prevRemotePrinters, currentRemotePrinters)) {
|
String[] currentRemotePrinters = getRemotePrintersNames();
|
||||||
|
if (doCompare(prevRemotePrinters, currentRemotePrinters)) {
|
||||||
|
|
||||||
// updated the printers data
|
// updated the printers data
|
||||||
// printers list now contains both local and network printer data
|
// printers list now contains both local and network printer data
|
||||||
refreshServices();
|
refreshServices();
|
||||||
|
|
||||||
// store the current data for next comparison
|
// store the current data for next comparison
|
||||||
prevRemotePrinters = currentRemotePrinters;
|
prevRemotePrinters = currentRemotePrinters;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prevRemotePrinters = getRemotePrintersNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -249,7 +249,7 @@ Java_sun_print_PrintServiceLookupProvider_getRemotePrintersNames(JNIEnv *env,
|
||||||
if (clazz == NULL) {
|
if (clazz == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
jobjectArray nameArray;
|
jobjectArray nameArray = NULL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
|
::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
|
||||||
|
@ -270,13 +270,14 @@ Java_sun_print_PrintServiceLookupProvider_getRemotePrintersNames(JNIEnv *env,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate space only for the network type printers
|
// return remote printers only if the list contains it.
|
||||||
nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL);
|
if (remotePrintersCount > 0) {
|
||||||
if (nameArray == NULL) {
|
// Allocate space only for the network type printers
|
||||||
throw std::bad_alloc();
|
nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL);
|
||||||
|
if (nameArray == NULL) {
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
nameArray = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop thro' network printers list only
|
// Loop thro' network printers list only
|
||||||
|
@ -298,7 +299,12 @@ Java_sun_print_PrintServiceLookupProvider_getRemotePrintersNames(JNIEnv *env,
|
||||||
|
|
||||||
delete [] pPrinterEnum;
|
delete [] pPrinterEnum;
|
||||||
delete [] pNetworkPrinterLoc;
|
delete [] pNetworkPrinterLoc;
|
||||||
return nameArray;
|
|
||||||
|
if (nameArray != NULL) {
|
||||||
|
return nameArray;
|
||||||
|
} else {
|
||||||
|
return env->NewObjectArray(0, clazz, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
CATCH_BAD_ALLOC_RET(NULL);
|
CATCH_BAD_ALLOC_RET(NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8153732
|
* @bug 8153732 8212202
|
||||||
* @requires (os.family == "Windows")
|
* @requires (os.family == "Windows")
|
||||||
* @summary Windows remote printer changes do not reflect in lookupPrintServices()
|
* @summary Windows remote printer changes do not reflect in lookupPrintServices()
|
||||||
* @ignore Requires a new network printer installation\removal
|
* @ignore Requires a new network printer installation\removal
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue