I get this error after runing a native image. Unsupported character encoding 'CP1252'
Spring Boot 3.0.2 Java 17 Mysql 5.7 Ubuntu 22.04
org.springframework.data.mapping.MappingException: Could not read value idusuario from result set
Caused by: java.sql.SQLException: Unsupported character encoding 'CP1252'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[na:na]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[na:na]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[na:na]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[na:na]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[na:na]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:85) ~[na:na]
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:891) ~[r2d2-attendance-dist:8.0.32]
at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1218) ~[r2d2-attendance-dist:8.0.32]
at com.zaxxer.hikari.pool.HikariProxyResultSet.getObject(HikariProxyResultSet.java) ~[na:na]
at org.springframework.jdbc.support.JdbcUtils.getResultSetValue(JdbcUtils.java:284) ~[na:na]
at org.springframework.data.jdbc.core.convert.ResultSetAccessor.getObject(ResultSetAccessor.java:93) ~[na:na]
... 58 common frames omitted
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Unsupported character encoding 'CP1252'
at java.base@17.0.5/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[r2d2-attendance-dist:na]
at java.base@17.0.5/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[r2d2-attendance-dist:na]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[na:na]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[na:na]
at com.mysql.cj.util.StringUtils.toString(StringUtils.java:1372) ~[na:na]
at com.mysql.cj.result.StringValueFactory.createFromBytes(StringValueFactory.java:139) ~[na:na]
at com.mysql.cj.result.StringValueFactory.createFromBytes(StringValueFactory.java:47) ~[na:na]
at com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeByteArray(MysqlTextValueDecoder.java:143) ~[na:na]
at com.mysql.cj.protocol.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:135) ~[r2d2-attendance-dist:8.0.32]
at com.mysql.cj.protocol.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:243) ~[r2d2-attendance-dist:8.0.32]
at com.mysql.cj.protocol.a.result.ByteArrayRow.getValue(ByteArrayRow.java:91) ~[na:na]
at com.mysql.cj.jdbc.result.ResultSetImpl.getString(ResultSetImpl.java:883) ~[r2d2-attendance-dist:8.0.32]
... 62 common frames omitted
Caused by: java.io.UnsupportedEncodingException: CP1252
at java.base@17.0.5/java.lang.String.lookupCharset(String.java:819) ~[r2d2-attendance-dist:na]
at java.base@17.0.5/java.lang.String.<init>(String.java:487) ~[r2d2-attendance-dist:na]
at com.mysql.cj.util.StringUtils.toString(StringUtils.java:1370) ~[na:na]
Comment From: viniciusfca
When a use the normal image ( jar) this erro not happens. I search before open this issue but I not found solution about this error.
Comment From: bclozel
This looks like a charset is loaded at runtime, but not detected during the build phase. It could be that the mysql driver is trying to load it dynamically in a way that it wasn't built in the native image.
You can configure your native build to include all charsets with the AddAllCharsets option. See this example for Gradle:
graalvmNative {
nativeBuild {
binaries {
main {
buildArgs.add('-H:+AddAllCharsets')
}
}
}
}
Can you try this and report back? I've added a note about this in the Spring Boot with GraalVM wiki page.
Comment From: viniciusfca
@bclozel Hi
Now it worked, thanks
I use maven so my configuration looks like this.
```sh
Comment From: wilkinsona
Thanks for following up, @viniciusfca. Looking at the MySQL driver's code, it will dynamically load charsets based on the encoding that's being used in the DB. This can't be predicted up front and will vary from application to application so I think that instructing Graal to add all charsets when needed is the best option here.