Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printers.putAll(...) clears NativePrinterMap #1189

Closed
tresf opened this issue Oct 10, 2023 · 1 comment · Fixed by #1124
Closed

printers.putAll(...) clears NativePrinterMap #1189

tresf opened this issue Oct 10, 2023 · 1 comment · Fixed by #1124
Assignees
Labels
Milestone

Comments

@tresf
Copy link
Contributor

tresf commented Oct 10, 2023

As identified in #1124 by @Vzor-, printers.putAll(...) will wipe out all entries of NativePrinterMap.

NativePrinterMap printers = NativePrinterMap.getInstance();
if (!printers.contains(defaultService)) {
printers.putAll(defaultService);
}

This is because NativePrinterMap.findMissing(...) performs a destructive operation:

public ArrayList<PrintService> findMissing(PrintService[] services) {
ArrayList<PrintService> serviceList = new ArrayList<>(Arrays.asList(services)); // shrinking list drastically improves performance
for(NativePrinter printer : values()) {
if (serviceList.contains(printer.getPrintService())) {
serviceList.remove(printer.getPrintService()); // existing match
} else {
printer.setOutdated(true); // no matches, mark to be removed
}
}
// remove outdated
for (Map.Entry<String, NativePrinter> entry : entrySet()) {
if(entry.getValue().isOutdated()) {
remove(entry.getKey());
}
}
// any remaining services are new/missing
return serviceList;
}

@tresf tresf added the bug label Oct 10, 2023
@tresf tresf added this to the 2.2.3 milestone Oct 10, 2023
@tresf
Copy link
Contributor Author

tresf commented Oct 11, 2023

This will be fixed by #1124, specifically a8beeba.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants