Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graalvm build failure #2414

Open
TruthBean opened this issue Dec 27, 2021 · 3 comments
Open

graalvm build failure #2414

TruthBean opened this issue Dec 27, 2021 · 3 comments

Comments

@TruthBean
Copy link

MyBatis version

3.5.9

Database vendor and version

mysql 5.7

Test case or example project

Steps to reproduce

  1. maven include mybatis
  2. package to a jar
  3. build with gralde
/opt/graalvm-ce-java17-21.3.0/bin/native-image \
--verbose --no-fallback -cp ./xxx-fat.jar \
-H:Name=websocket -H:Class=xxx.xxx.Application -H:+ReportUnsupportedElementsAtRuntime \
-H:+ReportExceptionStackTraces --allow-incomplete-classpath --enable-url-protocols=http \
-H:+PrintClassInitialization \
-J--add-exports=java.management/sun.management=ALL-UNNAMED \
--trace-class-initialization=org.apache.ibatis.type.JdbcType

Expected result

build success

Actual result

com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
org.apache.ibatis.type.JdbcType was unintentionally initialized at build time. org.apache.ibatis.type.JdbcType caused initialization of this class with the following trace:
at org.apache.ibatis.type.JdbcType.(JdbcType.java:30)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Unknown Source)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:568)
at java.lang.Class.getEnumConstantsShared(Class.java:3837)
at java.lang.Class.enumConstantDirectory(Class.java:3859)
at java.lang.Enum.valueOf(Enum.java:267)
at sun.reflect.annotation.AnnotationParser.parseEnumValue(AnnotationParser.java:479)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:344)
at java.lang.reflect.Method.getDefaultValue(Method.java:717)
at sun.reflect.annotation.AnnotationType.(AnnotationType.java:133)
at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85)
at com.oracle.svm.core.code.MethodMetadataEncoder.prepareMetadataForClass(MethodMetadataEncoder.java:107)
at com.oracle.svm.core.code.CodeInfoEncoder.prepareMetadataForClass(CodeInfoEncoder.java:240)
at com.oracle.svm.hosted.image.NativeImageCodeCache.buildRuntimeMetadata(NativeImageCodeCache.java:230)
at com.oracle.svm.hosted.image.LIRNativeImageCodeCache.layoutMethods(LIRNativeImageCodeCache.java:106)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:608)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:599)

at com.oracle.svm.core.util.UserError.abort(UserError.java:73)
at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:555)
at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.afterImageWrite(ClassInitializationFeature.java:316)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$8(NativeImageGenerator.java:663)
at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:73)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:663)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:599)
@TruthBean
Copy link
Author

solution:
change org.apache.ibatis.type.JdbcType.codeLookup to delayed filling

private final static Map<Integer,JdbcType> codeLookup = new HashMap<>();

  JdbcType(int code) {
    this.TYPE_CODE = code;
  }

  public static JdbcType forCode(int code)  {
    if (codeLookup.isEmpty()) {
      for (JdbcType type : JdbcType.values()) {
        codeLookup.put(type.TYPE_CODE, type);
      }
    }
    return codeLookup.get(code);
  }

@linghengqian
Copy link

linghengqian commented Jun 13, 2022

Mybatis provides support for different modules in both Spring Native and Quarkus, and I don't think the corresponding GraalVM json file should be added to mybatis itself.

@xuxiaowei-com-cn
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants