Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ public int getNumSamples() {
* Removes all filters currently added to this processor.
*/
public void removeAllFilters() {
for (Filter filter : filters.getArray()) {
filter.cleanup(renderer);
}
filters.clear();
updateLastFilterIndex();
Comment on lines +677 to 681
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This loop is not robust against exceptions from filter.cleanup(). If a cleanup call fails, subsequent filters won't be cleaned up, and the filter list won't be cleared, leaving the processor in an inconsistent state. To improve robustness, it's better to ensure all filters are attempted to be cleaned up and that filters.clear() is always called. Any exceptions during cleanup can be collected and re-thrown at the end.

Suggested change
for (Filter filter : filters.getArray()) {
filter.cleanup(renderer);
}
filters.clear();
updateLastFilterIndex();
java.util.List<Throwable> exceptions = new java.util.ArrayList<>();
for (Filter filter : filters.getArray()) {
try {
filter.cleanup(renderer);
} catch (Throwable t) {
exceptions.add(t);
}
}
filters.clear();
updateLastFilterIndex();
if (!exceptions.isEmpty()) {
RuntimeException toThrow = new RuntimeException("One or more filters failed to clean up.");
for (Throwable t : exceptions) {
toThrow.addSuppressed(t);
}
throw toThrow;
}

}
Expand Down
Loading