apache / apache/maven-filtering
Improve error message for MalformedInputException during resource filtering
- Dominant language
- Java
- Stars
- 9
- Forks
- 36
- Avg merge
- 8h 47m
- Merged PRs (30d)
- 4
Description
### 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:
```
4.0.0
com.example
encoding-test
1.0-SNAPSHOT
jar
org.apache.maven.plugins
maven-resources-plugin
3.5.0
UTF-8
src/main/resources
true
```
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
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.