Skip to content

Maven uses system default encoding for maven.config #11258

@hvoynov

Description

@hvoynov

Affected version

3.9.11

Bug description

Maven 3.9.11 reads the maven.properties file using the system's default encoding instead of UTF-8, causing issues with non-ASCII characters (e.g., Cyrillic). This leads to incorrect processing of properties containing such characters.

To Reproduce

Create a maven.properties file with non-ASCII characters (e.g., key=ая).
Run Maven with mvn -version or any command that loads maven.properties.
You will get following:

[ERROR] Error executing Maven.
java.io.UncheckedIOException: java.nio.charset.UnmappableCharacterException: Input length = 1
	at java.io.BufferedReader$1.hasNext(BufferedReader.java:574)
	at java.util.Iterator.forEachRemaining(Iterator.java:115)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:546)
	at java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
	at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:438)
	at org.apache.maven.cli.MavenCli.cli(MavenCli.java:386)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:272)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314)
Caused by: java.nio.charset.UnmappableCharacterException: Input length = 1
	at java.nio.charset.CoderResult.throwException(CoderResult.java:282)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
	at java.io.InputStreamReader.read(InputStreamReader.java:184)
	at java.io.BufferedReader.fill(BufferedReader.java:161)
	at java.io.BufferedReader.readLine(BufferedReader.java:324)
	at java.io.BufferedReader.readLine(BufferedReader.java:389)
	at java.io.BufferedReader$1.hasNext(BufferedReader.java:571)
	... 18 more

Expected behavior

Maven should read maven.properties in UTF-8 encoding by default to properly handle non-ASCII characters.

Explicitly setting -Dfile.encoding=UTF-8 in MAVEN_OPTS or jvm.config resolves the issue for maven.properties. Explicitly setting -Dfile.encoding=windows-1251 (also tested with BIG5) can be used for reproduce.

Environment

Windows 10,
file.encoding=windows-1251
Java version: 1.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions