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 issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/apple/pkl/pull/1198
**Author:** [@netvl](https://github.com/netvl)
**Created:** 9/4/2025
**Status:** ✅ Merged
**Merged:** 9/5/2025
**Merged by:** [@bioball](https://github.com/bioball)
**Base:** `main` ← **Head:** `ca-classloading-fix`
---
### 📝 Commits (1)
- [`e35c104`](https://github.com/apple/pkl/commit/e35c1040b6a6625b6d4637cb31e972a99a8a2da9) Fixed fallback certificates not working in certain classloader setups
### 📊 Changes
**1 file changed** (+3 additions, -2 deletions)
<details>
<summary>View changed files</summary>
📝 `pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt` (+3 -2)
</details>
### 📄 Description
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.
Closes https://github.com/apple/pkl/issues/1199
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/1198
Author: @netvl
Created: 9/4/2025
Status: ✅ Merged
Merged: 9/5/2025
Merged by: @bioball
Base:
main← Head:ca-classloading-fix📝 Commits (1)
e35c104Fixed fallback certificates not working in certain classloader setups📊 Changes
1 file changed (+3 additions, -2 deletions)
View changed files
📝
pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt(+3 -2)📄 Description
In the original implementation the
org/pkl/commons/cli/PklCARoots.pemresource is resolved relatively to the classloader associated with the class returned byjavaClass. However, since this is an extension method forHttpClient.Builder, it means callingjavaClasson 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
javaClassagainstthis@CliCommand, to use the classloader which loaded the jar with theCliCommandclass to find the CA resource.Closes https://github.com/apple/pkl/issues/1199
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.