Open cushon opened 6 months ago
I don't think this is an issue with native-images, so much as a particularly bad hack in kotlinc.
From my own experiments, this section tries to dynamically discover from where to load certain kotlinc config files. One of the possible locations is from a classpath JAR of the executing program. To check that case, kotlinc first tries to load the class file of a class known to be in that same JAR (PathUtilKt
) as a resource. If that succeeds, it treats the matching JAR as an archive, and loads the config using ZIP file APIs. (This is at least one pathology. There are others using the same PathUtilKt
trick.)
For native images, this technique can't work. Even if PathUtilKt.class
is kept as a resource, there will be not be a JAR in the filesystem.
One of the tip-offs in the error message is the resource:
prefix. kotlinc has logic for resolving a few different URI
schemes to config file locations. However, resource
is not a supported scheme. Native-image conversion seems to lead to suchURI
s being created at runtime, when they would not be during execution on a JVM.
Describe the issue
I am trying to create a native image for https://github.com/facebook/ktfmt. The native image fails at runtime with a 'Resource not found' error, despite native-image-agent generating a
resource-config.json
that seems to include the resource.This looks like the same issue as https://github.com/oracle/graal/issues/4691, which was closed due to inactivity. I am filing a new issue as suggested in https://github.com/oracle/graal/issues/4691#issuecomment-1820739658 since this still reproduces with recent GraalVM versions, and I have included steps to reproduce below.
Steps to reproduce the issue
org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment$Companion.class
is listed in the generatedresource-config.json
:I experimented with using
--initialize-at-build-time
as suggested in https://github.com/oracle/graal/issues/4691#issuecomment-1211745569, but couldn't find an invocation ofnative-image
that succeeded.Describe GraalVM and your environment: