This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 991728f Fix #284: invalidate the cache when suppressionsLocation
changes (#732)
991728f is described below
commit 991728f23db6bd7c7e32dc8ceec86bb342ef9511
Author: Arturo Bernal <[email protected]>
AuthorDate: Sun Nov 22 12:56:28 2026 +0100
Fix #284: invalidate the cache when suppressionsLocation changes (#732)
DefaultCheckstyleExecutor pre-parsed the suppressionsLocation file
into a plain FilterSet and added it to the Checker directly. A
FilterSet does not implement Checkstyle's ExternalResourceHolder, so
Checker.process() never discovered the suppressions file as an
external resource to hash - edits to it never changed the cache key,
so a cached run kept reporting whatever suppression result it had the
first time, even after the suppressions file changed to no longer
suppress a violation.
Declaring suppressions through the checker configuration (a
<module name="SuppressionFilter"> with a file property) already
worked, because that module does implement ExternalResourceHolder.
This builds the exact same SuppressionFilter module and configures it
the way Checkstyle itself would from that declaration, instead of
pre-loading the suppressions into a FilterSet, so the plugin's
suppressionsLocation parameter gets the same cache behavior.
Added an integration test (MCHECKSTYLE-372-suppressions-cache) that
runs checkstyle:check once with a suppressions file that suppresses a
violation, then rebuilds (no clean, same cache) with a suppressions
file that doesn't - confirmed it passed wrongly with the old code and
now fails as expected. Full test suite, checkstyle, spotless and rat
pass locally.
Claude-Session: https://claude.ai/code/session_0153qyh22xBMN1vPfWGz3jSH
---
.../checkstyle.xml | 26 ++++++++
.../invoker.properties | 20 ++++++
src/it/MCHECKSTYLE-372-suppressions-cache/pom.xml | 76 ++++++++++++++++++++++
.../src/main/java/demo/Foo.java | 24 +++++++
.../suppressions-ok.xml | 23 +++++++
.../suppressions-violation.xml | 23 +++++++
.../checkstyle/exec/DefaultCheckstyleExecutor.java | 35 ++++++++--
7 files changed, 220 insertions(+), 7 deletions(-)
diff --git a/src/it/MCHECKSTYLE-372-suppressions-cache/checkstyle.xml
b/src/it/MCHECKSTYLE-372-suppressions-cache/checkstyle.xml
new file mode 100644
index 0000000..f0619fc
--- /dev/null
+++ b/src/it/MCHECKSTYLE-372-suppressions-cache/checkstyle.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
+<module name="Checker">
+ <module name="RegexpSingleline">
+ <property name="format" value="FIXME"/>
+ <property name="message" value="Found FIXME marker"/>
+ </module>
+</module>
diff --git a/src/it/MCHECKSTYLE-372-suppressions-cache/invoker.properties
b/src/it/MCHECKSTYLE-372-suppressions-cache/invoker.properties
new file mode 100644
index 0000000..27922e4
--- /dev/null
+++ b/src/it/MCHECKSTYLE-372-suppressions-cache/invoker.properties
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals.1 = verify
+invoker.goals.2 = verify -Ptrigger-violation
+invoker.buildResult.2 = failure
diff --git a/src/it/MCHECKSTYLE-372-suppressions-cache/pom.xml
b/src/it/MCHECKSTYLE-372-suppressions-cache/pom.xml
new file mode 100644
index 0000000..e2dacc7
--- /dev/null
+++ b/src/it/MCHECKSTYLE-372-suppressions-cache/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.checkstyle</groupId>
+ <artifactId>MCHECKSTYLE-372-suppressions-cache</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <url>http://maven.apache.org/</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <!--
+ No profile active: suppressions-ok.xml suppresses the one violation
below. The "trigger-violation"
+ profile, active only for the second invocation, switches to
suppressions-violation.xml, which does
+ not - without MCHECKSTYLE-372's fix, the first invocation's cache made
checkstyle:check ignore that
+ change and report the build as clean regardless.
+ -->
+
<checkstyle.suppressions.file>suppressions-ok.xml</checkstyle.suppressions.file>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <configLocation>checkstyle.xml</configLocation>
+
<suppressionsLocation>${checkstyle.suppressions.file}</suppressionsLocation>
+ <failOnViolation>true</failOnViolation>
+ <violationSeverity>warning</violationSeverity>
+ </configuration>
+ <executions>
+ <execution>
+ <id>check</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>trigger-violation</id>
+ <properties>
+
<checkstyle.suppressions.file>suppressions-violation.xml</checkstyle.suppressions.file>
+ </properties>
+ </profile>
+ </profiles>
+</project>
diff --git
a/src/it/MCHECKSTYLE-372-suppressions-cache/src/main/java/demo/Foo.java
b/src/it/MCHECKSTYLE-372-suppressions-cache/src/main/java/demo/Foo.java
new file mode 100644
index 0000000..10165e7
--- /dev/null
+++ b/src/it/MCHECKSTYLE-372-suppressions-cache/src/main/java/demo/Foo.java
@@ -0,0 +1,24 @@
+package demo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class Foo {
+ // FIXME this should trigger when not suppressed
+}
diff --git a/src/it/MCHECKSTYLE-372-suppressions-cache/suppressions-ok.xml
b/src/it/MCHECKSTYLE-372-suppressions-cache/suppressions-ok.xml
new file mode 100644
index 0000000..2fdd7c9
--- /dev/null
+++ b/src/it/MCHECKSTYLE-372-suppressions-cache/suppressions-ok.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter
Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">
+<suppressions>
+ <suppress checks="RegexpSingleline" files="Foo.java"/>
+</suppressions>
diff --git
a/src/it/MCHECKSTYLE-372-suppressions-cache/suppressions-violation.xml
b/src/it/MCHECKSTYLE-372-suppressions-cache/suppressions-violation.xml
new file mode 100644
index 0000000..27a7789
--- /dev/null
+++ b/src/it/MCHECKSTYLE-372-suppressions-cache/suppressions-violation.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter
Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">
+<suppressions>
+ <suppress checks="RegexpSingleline" files="NoSuchFile.java"/>
+</suppressions>
diff --git
a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
index 837d711..e7036b7 100644
---
a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
+++
b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
@@ -45,8 +45,8 @@ import com.puppycrawl.tools.checkstyle.PropertiesExpander;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Configuration;
-import com.puppycrawl.tools.checkstyle.api.FilterSet;
-import com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader;
+import com.puppycrawl.tools.checkstyle.api.Filter;
+import com.puppycrawl.tools.checkstyle.filters.SuppressionFilter;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -106,7 +106,7 @@ public class DefaultCheckstyleExecutor implements
CheckstyleExecutor {
}
final String suppressionsFilePath = getSuppressionsFilePath(request);
- FilterSet filterSet = getSuppressionsFilterSet(suppressionsFilePath);
+ Filter suppressionFilter =
createSuppressionFilter(suppressionsFilePath);
Checker checker = new Checker();
@@ -156,8 +156,8 @@ public class DefaultCheckstyleExecutor implements
CheckstyleExecutor {
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
- if (filterSet != null) {
- checker.addFilter(filterSet);
+ if (suppressionFilter != null) {
+ checker.addFilter(suppressionFilter);
}
Configuration configuration = getConfiguration(request);
checker.configure(configuration);
@@ -581,16 +581,37 @@ public class DefaultCheckstyleExecutor implements
CheckstyleExecutor {
}
}
- private FilterSet getSuppressionsFilterSet(final String
suppressionsFilePath) throws CheckstyleExecutorException {
+ /**
+ * Builds a {@code SuppressionFilter} module configured with the given
suppressions file, the same way
+ * Checkstyle builds one when it is declared as a module in the checker
configuration.
+ * <p>
+ * This matters for the cache file (MCHECKSTYLE-372): Checkstyle
invalidates its cache for an external
+ * resource only when the module holding it implements {@code
ExternalResourceHolder}, which
+ * {@code SuppressionFilter} does but a pre-parsed {@code FilterSet} does
not. Loading the suppressions
+ * ourselves and adding the result as a plain {@code FilterSet} - as this
method used to - left Checkstyle
+ * with no way to notice the suppressions file had changed, so edits to it
were silently ignored as long
+ * as the cache file was still considered up to date for everything else.
+ *
+ * @param suppressionsFilePath absolute path to the suppressions file, or
{@code null} if none configured
+ * @return the configured filter, or {@code null} if {@code
suppressionsFilePath} is {@code null}
+ * @throws CheckstyleExecutorException if the suppressions file cannot be
loaded
+ */
+ private Filter createSuppressionFilter(final String suppressionsFilePath)
throws CheckstyleExecutorException {
if (suppressionsFilePath == null) {
return null;
}
+ SuppressionFilter suppressionFilter = new SuppressionFilter();
+ DefaultConfiguration suppressionFilterConfig = new
DefaultConfiguration("SuppressionFilter");
+ suppressionFilterConfig.addProperty("file", suppressionsFilePath);
+
try {
- return SuppressionsLoader.loadSuppressions(suppressionsFilePath);
+ suppressionFilter.configure(suppressionFilterConfig);
} catch (CheckstyleException ce) {
throw new CheckstyleExecutorException("Failed to load suppressions
file from: " + suppressionsFilePath, ce);
}
+
+ return suppressionFilter;
}
private String getSuppressionsFilePath(final CheckstyleExecutorRequest
request) throws CheckstyleExecutorException {