harwey/cups4j

cups printer getPrinterState() returns 'null'

Opened this issue · 4 comments

I am using 0.7.8 release along with CUPS v2.2.1. However when I try to get the state of a printer I get 'null' value. I have investigated and found that in class 'PrinterStateEnum' you've compared incoming state value (string, eg 'idle') with toString of enum getValue. If you see your enum declaration the values are in integer, however the incoming state value is string - something like 'idle' or so. Hence we get a 'null' assigned to printer state as if condition fails. For example see below code, so instead of using getValue, getStateName should solve this issue.

for (PrinterStateEnum printerState : PrinterStateEnum.values()) {
System.out.println(printerState.getValue().toString());
}

output: 3 4 5

for (PrinterStateEnum printerState : PrinterStateEnum.values()) {
System.out.println(printerState.getStateName().toString());
}

output: idle printing stopped

I have created a pull request - #53

I m seeing same behaviour. it will be nice if the next release included this fix.

Even after your fix @rajibdk , getPrinterState still returns null. what you fixed is the method getState().
Although i am using CUPS 2.2.10

it sounds to me like there may be a printer state value that cups4j does not know about (yet) - and therefor the state parser returns null.