You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/09/29 09:27:09 UTC

(maven-resources-plugin) branch master updated: fix: clarify error message when binary resource filtering fails

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resources-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 8015375  fix: clarify error message when binary resource filtering fails
8015375 is described below

commit 801537553b9228570ce5ba5997e88496f467106d
Author: Efe <go...@gmail.com>
AuthorDate: Tue Sep 29 12:27:03 2026 +0300

    fix: clarify error message when binary resource filtering fails
    
    - Improve exception message to explain that binary files cannot be text-filtered
    - Apply spotless formatting to ResourcesMojoTest
---
 .../maven/plugins/resources/ResourcesMojo.java      | 21 ++++++++++++++++++++-
 .../maven/plugins/resources/ResourcesMojoTest.java  | 13 +++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
index 79140d3..8d3f323 100644
--- a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
@@ -18,6 +18,7 @@
  */
 package org.apache.maven.plugins.resources;
 
+import java.nio.charset.MalformedInputException;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -480,10 +481,28 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo {
 
             executeUserFilterComponents(mavenResourcesExecution);
         } catch (MavenFilteringException e) {
-            throw new MojoException(e.getMessage(), e);
+            throw new MojoException(filteringFailureMessage(e), e);
         }
     }
 
+    static String filteringFailureMessage(MavenFilteringException exception) {
+        if (hasCause(exception, MalformedInputException.class)) {
+            return exception.getMessage()
+                    + ". The resource may be binary; configure its extension in nonFilteredFileExtensions "
+                    + "or disable filtering for it.";
+        }
+        return exception.getMessage();
+    }
+
+    private static boolean hasCause(Throwable failure, Class<? extends Throwable> type) {
+        for (Throwable cause = failure; cause != null; cause = cause.getCause()) {
+            if (type.isInstance(cause)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * This solves https://issues.apache.org/jira/browse/MRESOURCES-99.<br/>
      * BUT:<br/>
diff --git a/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java b/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java
index 67a04b4..ac833a4 100644
--- a/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoTest.java
@@ -21,6 +21,7 @@ package org.apache.maven.plugins.resources;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.MalformedInputException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -38,6 +39,7 @@ import org.apache.maven.api.plugin.testing.MojoTest;
 import org.apache.maven.api.plugin.testing.stubs.SessionMock;
 import org.apache.maven.impl.InternalSession;
 import org.apache.maven.plugins.resources.stub.MavenProjectResourcesStub;
+import org.apache.maven.shared.filtering.MavenFilteringException;
 import org.apache.maven.shared.filtering.Resource;
 import org.junit.jupiter.api.Test;
 
@@ -51,6 +53,17 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 @MojoTest
 class ResourcesMojoTest {
 
+    @Test
+    void malformedInputExplainsHowToHandleBinaryResources() {
+        MavenFilteringException exception =
+                new MavenFilteringException("Input length = 1", new IOException(new MalformedInputException(1)));
+
+        assertEquals(
+                "Input length = 1. The resource may be binary; configure its extension in "
+                        + "nonFilteredFileExtensions or disable filtering for it.",
+                ResourcesMojo.filteringFailureMessage(exception));
+    }
+
     private static final String CONFIG_XML = "classpath:/unit/resources-test/plugin-config.xml";
 
     /**