[MNG-2187] Improve error message when the pom is encoded in the wrong charset

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@929140 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-03-30 13:48:08 +00:00
parent 912a565ffc
commit 9020e459a1
1 changed files with 14 additions and 1 deletions

View File

@ -359,7 +359,20 @@ public class DefaultModelBuilder
}
catch ( IOException e )
{
problems.add( Severity.FATAL, "Non-readable POM " + modelSource.getLocation() + ": " + e.getMessage(), e );
String msg = e.getMessage();
if ( msg == null || msg.length() <= 0 )
{
// NOTE: There's java.nio.charset.MalformedInputException and sun.io.MalformedInputException
if ( e.getClass().getName().endsWith( "MalformedInputException" ) )
{
msg = "Some input bytes do not match the file encoding.";
}
else
{
msg = e.getClass().getSimpleName();
}
}
problems.add( Severity.FATAL, "Non-readable POM " + modelSource.getLocation() + ": " + msg, e );
throw new ModelBuildingException( problems.getRootModelId(), problems.getProblems() );
}