mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Fixed fallback certificates not working in certain classloader setups (#1198)
In the original implementation the `org/pkl/commons/cli/PklCARoots.pem` resource is resolved relatively to the classloader associated with the class returned by `javaClass`. However, since this is an extension method for `HttpClient.Builder`, it means calling `javaClass` on the builder instance, which is actually defined in the system classpath. Because of this, if the Pkl class is loaded by a different classloader compared to the one which contains JDK classes, which is totally possible in certain scenarios (e.g. with Gradle), then this resource resolution will fail. The solution is to resolve `javaClass` against `this@CliCommand`, to use the classloader which loaded the jar with the `CliCommand` class to find the CA resource.
This commit is contained in:
@@ -218,8 +218,9 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) {
|
||||
}
|
||||
if (!certsAdded) {
|
||||
val defaultCerts =
|
||||
javaClass.classLoader.getResourceAsStream("org/pkl/commons/cli/PklCARoots.pem")
|
||||
?: throw CliException("Could not find bundled certificates")
|
||||
this@CliCommand.javaClass.classLoader.getResourceAsStream(
|
||||
"org/pkl/commons/cli/PklCARoots.pem"
|
||||
) ?: throw CliException("Could not find bundled certificates")
|
||||
addCertificates(defaultCerts.readAllBytes())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user