ban-xiu opened a new issue, #327:
URL: https://github.com/apache/maven-filtering/issues/327
### Affected version
3.x
### Bug description
# Issue Description
When Maven's maven-resources-plugin filters resource files, if the file
encoding doesn't match the configured encoding, it throws
MalformedInputException: Input length = 1. However, the exception message
doesn't clearly indicate the encoding issue.
# Root Cause
In maven-filtering's FilteringUtils.copyFile() method,
Files.newBufferedReader() reads files with the specified encoding. When file
bytes don't conform to that encoding, wrapped.read() throws
MalformedInputException without including encoding information in the error
message.
# Minimum reproduction example
project:
```
encoding-test/
├── pom.xml
└── src/
└── main/
└── resources/
└── test.txt // use gbk
```
pom:
```
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>encoding-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
```
cmd:
```
mvn clean resources:resources
```
log:
```
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.example:encoding-test
>----------------------
[INFO] Building encoding-test 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar
]---------------------------------
[INFO]
[INFO] --- clean:3.2.0:clean (default-clean) @ encoding-test ---
[INFO] Deleting D:\JavaProjects\maven-filtering-coding-test\target
[INFO]
[INFO] --- resources:3.5.0:resources (default-cli) @ encoding-test ---
[INFO] Copying 2 resources from src\main\resources to target\classes
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 2.465 s
[INFO] Finished at: 2026-03-08T16:41:01+08:00
[INFO]
------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-resources-plugin:3.5.0:resources (default-cli)
on project encoding-test: filtering D:\JavaProjects\
maven-filtering-coding-test\src\main\resources\test.txt to
D:\JavaProjects\maven-filtering-coding-test\target\classes\test.txt failed with
MalformedInputException: Input length = 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please
read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]