diff --git a/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/logging/LoggingTester.java b/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/logging/LoggingTester.java index eac882771bf..eed565167f4 100644 --- a/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/logging/LoggingTester.java +++ b/org.eclipse.xtext.junit4/src/org/eclipse/xtext/junit4/logging/LoggingTester.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2022 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -333,16 +333,18 @@ private static List appenderHierarchy(Logger logger) { } private static void removeFilter(Appender appender, Filter filter) { - if (Objects.equal(appender.getFilter(), filter)) { - appender.clearFilters(); - appender.addFilter(filter.getNext()); - } else { - for (Filter current = appender.getFilter(); (current != null); current = current.getNext()) { - if (Objects.equal(current.getNext(), filter)) { - current.setNext(filter.getNext()); - return; - } + List filtersToKeep = new ArrayList<>(); + Filter present = appender.getFilter(); + while (present != null) { + if (!Objects.equal(present, filter)) { + filtersToKeep.add(present); } + present = present.getNext(); + } + appender.clearFilters(); + for(Filter addMe: filtersToKeep) { + addMe.setNext(null); + appender.addFilter(addMe); } } diff --git a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/logging/LoggingTester.java b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/logging/LoggingTester.java index ca0b24ea9dc..86f01e365b6 100644 --- a/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/logging/LoggingTester.java +++ b/org.eclipse.xtext.testing/src/org/eclipse/xtext/testing/logging/LoggingTester.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -69,17 +69,19 @@ private static List appenderHierarchy(Logger logger) { } private static void removeFilter(Appender appender, Filter filter) { - if (Objects.equals(appender.getFilter(), filter)) { - appender.clearFilters(); - appender.addFilter(filter.getNext()); - } else { - for (Filter current = appender.getFilter(); current != null; current = current.getNext()) { - if (Objects.equals(current.getNext(), filter)) { - current.setNext(filter.getNext()); - return; - } + List filtersToKeep = new ArrayList<>(); + Filter present = appender.getFilter(); + while (present != null) { + if (!Objects.equals(present, filter)) { + filtersToKeep.add(present); } + present = present.getNext(); } + appender.clearFilters(); + filtersToKeep.forEach(addMe -> { + addMe.setNext(null); + appender.addFilter(addMe); + }); } public static class LogCapture {