java.lang.IllegalArgumentException: Malformed \uxxxx encoding
Problem Statement
The java.lang.IllegalArgumentException: Malformed \uxxxx encoding
error occurs during Maven builds when corrupted property files in your local Maven repository contain malformed Unicode escape sequences. This typically happens with the resolver-status.properties
files that Maven uses to track dependency resolution status.
The error manifests as a build failure with a stack trace showing:
java.lang.IllegalArgumentException: Malformed \uxxxx encoding.
at java.util.Properties.loadConvert(Properties.java:672)
at java.util.Properties.load0(Properties.java:455)
at java.util.Properties.load(Properties.java:408)
Root Cause
This error occurs due to a known Maven resolver bug (MRESOLVER-216) where multiple threads may simultaneously attempt to resolve the same artifact, corrupting the resolver-status.properties
files with invalid Unicode characters like \u0000
.
Solutions
Quick Fix: Delete Corrupted Files
The most common solution is to locate and delete the corrupted resolver-status.properties
files:
# Find and delete all resolver-status.properties files
find ~/.m2 -name "resolver-status.properties" -delete
# Find corrupted files
FINDSTR /S /M "u0" resolver-status.properties
# Then manually delete the files listed
Targeted Cleanup
For a more targeted approach that only removes corrupted files:
# Search for files containing malformed Unicode sequences
grep -rnw ~/.m2 -e '\u0000'
# Delete only the corrupted files
find ~/.m2 -name "resolver-status.properties" -exec grep -H -e '\u0000' {} \; | sed -r 's/:.*$//g' | xargs rm
Complete Repository Reset
If the issue persists, you can delete your entire Maven repository:
rm -rf ~/.m2/repository
WARNING
This will force Maven to download all dependencies again, which may take significant time depending on your internet connection and project size.
Prevent Recurrence
To prevent future occurrences, configure Maven to use a single thread for dependency resolution:
mvn clean install -Daether.metadataResolver.threads=1
For IntelliJ IDEA users, configure this in: Settings → Build, Execution, Deployment → Maven → Runner → VM Options Add: -Daether.metadataResolver.threads=1
Advanced Debugging
If you need to identify the exact corrupted file:
Run Maven with debug logging:
bashmvn clean install -e -X
Look for dependency resolution errors in the output
Use your IDE's debugger to set a breakpoint at
java.util.Properties.loadConvert()
(line 672) to inspect the corrupted file path during execution
Verification
After applying any solution, verify the fix by running:
mvn clean compile
The build should complete successfully without the encoding error.
Conclusion
The "Malformed \uxxxx encoding" error is typically caused by corrupted metadata files in your Maven repository. The most effective solutions involve:
- Deleting corrupted
resolver-status.properties
files - Preventing concurrency issues with
-Daether.metadataResolver.threads=1
- As a last resort, clearing the entire Maven repository
This approach resolves the issue while minimizing disruption to your development workflow.