Skip to content

Cannot construct instance of java.nio.file.Path with GraalVM Native Image #3725

@tisonkun

Description

@tisonkun

Reproduce

https://github.com/tisonkun/hawkeye/tree/repro-jackson-native

# Use GraalVM 22.3.0
./mvnw clean package -DskipTests -Pnative
./distribution/native/target/hawkeye-native check

... throws:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.nio.file.Path` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
 at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: io.korandoru.hawkeye.core.HawkEyeConfig$HawkEyeConfigBuilder["baseDir"])
	at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1909)
	at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:408)
	at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1354)
	at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:274)
	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeSetAndReturn(MethodProperty.java:158)
	at com.fasterxml.jackson.databind.deser.BuilderBasedDeserializer.vanillaDeserialize(BuilderBasedDeserializer.java:293)
	at com.fasterxml.jackson.databind.deser.BuilderBasedDeserializer.deserialize(BuilderBasedDeserializer.java:217)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4730)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3542)
	at io.korandoru.hawkeye.core.HawkEyeConfig.of(HawkEyeConfig.java:65)
	at io.korandoru.hawkeye.command.HawkEyeCommandCheck.call(HawkEyeCommandCheck.java:42)
	at io.korandoru.hawkeye.command.HawkEyeCommandCheck.call(HawkEyeCommandCheck.java:28)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
	at picocli.CommandLine.access$1300(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
	at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
	at picocli.CommandLine.execute(CommandLine.java:2078)
	at io.korandoru.hawkeye.command.HawkEyeCommandMain.main(HawkEyeCommandMain.java:35)

picocli provides picocli-codegen to generate Native Image configs file. I wonder whether jackson ecosystem has a similar solution or how I can properly config it.

It seems that NioPathDeserializer isn't contained in the final image due to inaccurate dead code analysis.

Ref: korandoru/hawkeye#18

Metadata

Metadata

Assignees

No one assigned

    Labels

    to-evaluateIssue that has been received but not yet evaluated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions