serpro69 / kotlin-faker

Port of a popular ruby faker gem written in kotlin. Generate realistically looking fake data such as names, addresses, banking details, and many more, that can be used for testing and data anonymization purposes.
https://serpro69.github.io/kotlin-faker/
MIT License
470 stars 43 forks source link

graal: Discovered unresolved method during parsing: java.nio.ByteBuffer.rewind() #157

Closed serpro69 closed 1 year ago

serpro69 commented 2 years ago
Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: java.nio.ByteBuffer.rewind(). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time.
Detailed message:
[faker-bot_0.0.0:615210]      [total]Trace:
:  19,156.22 ms,  3.22 GB
        at parsing faker.com.fasterxml.jackson.databind.ser.std.ByteBufferSerializer.serialize(ByteBufferSerializer.java:31)
Call path from entry point to faker.com.fasterxml.jackson.databind.ser.std.ByteBufferSerializer.serialize(ByteBuffer, JsonGenerator, SerializerProvider):
        at faker.com.fasterxml.jackson.databind.ser.std.ByteBufferSerializer.serialize(ByteBufferSerializer.java:22)
        at faker.com.fasterxml.jackson.databind.ser.std.ByteBufferSerializer.serialize(ByteBufferSerializer.java:13)
        at faker.com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:468)
        at faker.com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:353)
        at faker.com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1516)
        at faker.com.fasterxml.jackson.databind.ObjectWriter._writeValueAndClose(ObjectWriter.java:1219)
        at faker.com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:1086)
        at faker.com.fasterxml.jackson.databind.node.InternalNodeMapper.nodeToString(InternalNodeMapper.java:30)
        at faker.com.fasterxml.jackson.databind.node.BaseJsonNode.toString(BaseJsonNode.java:136)
        at java.lang.String.valueOf(String.java:2994)
        at java.nio.charset.IllegalCharsetNameException.<init>(IllegalCharsetNameException.java:55)
        at java.nio.charset.Charset.checkName(Charset.java:303)
        at com.oracle.svm.core.jdk.localization.substitutions.Target_java_nio_charset_Charset.lookup(Target_java_nio_charset_Charset.java:77)
        at java.nio.charset.Charset.isSupported(Charset.java:505)
        at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST:Ljava_nio_charset_Charset_2_0002eisSupported_00028Ljava_lang_String_2_00029Z(generated:0)

Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
# Printing build artifacts to: /home/sergio/Projects/personal/personal/kotlin-faker/cli-bot/build/graal/faker-bot_0.0.0.build_artifacts.txt
Error: Image build request failed with exit status 1

seems to be caused by a recent jackson version update - https://github.com/serpro69/kotlin-faker/commit/3d5f71ae540b8a3d7e45905b8df568c8ca435263 build run - https://github.com/serpro69/kotlin-faker/actions/runs/3303548647

serpro69 commented 2 years ago

agentlib does not seem to detect the ByteBuffer usage, hence tried to fix reflect-config.json manually by adding:

  {
    "name": "java.nio.Buffer",
    "methods": [
      {
        "name": "rewind"
      }
    ]
  },
  {
    "name": "java.nio.ByteBuffer",
    "methods": [
      {
        "name": "rewind"
      }
    ]
  },

This causes a different error:

> Task :cli-bot:nativeImage
Warning: Ignoring server-mode native-image argument --no-server.
[faker-bot_0.0.0:624051]    classlist:   1,631.40 ms,  1.59 GB
[faker-bot_0.0.0:624051]        (cap):     512.28 ms,  2.17 GB
[faker-bot_0.0.0:624051]        setup:   1,095.86 ms,  2.17 GB
Error: Error parsing reflection configuration in jar:file:/home/sergio/Projects/personal/personal/kotlin-faker/cli-bot/build/libs/cli-bot-0.0.0.jar!/META-INF/native-image/io.github.serpro69/cli-bot/reflect-config.json:
Method java.nio.ByteBuffer.rewind() not found
[faker-bot_0.0.0:624051]      [total]: Verify that the configuration matches the schema described in the -H:PrintFlags=+ output for option ReflectionConfigurationResources.
  2,769.28 ms,  2.17 GB
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
# Printing build artifacts to: /home/sergio/Projects/personal/personal/kotlin-faker/cli-bot/build/graal/faker-bot_0.0.0.build_artifacts.txt
Error: Image build request failed with exit status 1

java.nio.ByteBuffer in fact does not contain a rewind method, it's inherited from java.nio.Buffer, hence this looks to be like an issue with graal. Not sure if a later version will fix it, might be worth a try, but as a temporary fix what seems to work is adding an --allow-incomplete-classpath option to graal config. This pushes the problem to runtime, but still seems to be working fine (since we're not calling that part of jackson), so should do as a "temporary" workaround (nothing more permanent than temporary, as they say)