JDK 17 (JEP 403 Strongly Encapsulate JDK Internals) breaks okhttp without additional config

See original GitHub issue
  • Version used
$ java --version                                                                                                                                      sgopal1@m-c02xd0kqjgh7
openjdk 17-loom 2021-09-14
OpenJDK Runtime Environment (build 17-loom+7-342)
OpenJDK 64-Bit Server VM (build 17-loom+7-342, mixed mode, sharing)

// OkHttp
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
implementation("com.squareup.okhttp3:okhttp")

Throws the following error when trying to create an OkHttpClient on JDK17-ea build with strong encapsulation enabled.

java.lang.reflect.InaccessibleObjectException: Unable to make field private final sun.security.ssl.SSLContextImpl sun.security.ssl.SSLSocketFactoryImpl.context accessible: module java.base does not "opens sun.security.ssl" to unnamed module @3a44f074
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
        at okhttp3.internal.Platform.readFieldOrNull(Platform.java:417)
        at okhttp3.internal.Platform.trustManager(Platform.java:91)
        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:184)
        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:60)
        at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:718)
        at se.bjurr.gitchangelog.internal.integrations.github.GitHubServiceFactory.getGitHubService(GitHubServiceFactory.java:55)

Have to explicitly open this package for reflection in all (--add-​opens java.base/sun.security.ssl=ALL-UNNAMED) the programs for okhttp to work properly.

Source: https://github.com/square/okhttp/blob/master/okhttp/src/main/kotlin/okhttp3/internal/platform/Platform.kt#L93

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
yschimkecommented, Jun 2, 2021

We should add a JDK17 CI build at the same time.

1reaction
swankjessecommented, Jun 3, 2021

Thanks for the great report!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Internal JDK Elements Strongly Encapsulated in JDK 17 - InfoQ
JEP 403 (Strongly Encapsulate JDK Internals) has been targeted for ... to OpenJDK to update internal code without breaking existing code.
Read more >
JEP 403: Strongly Encapsulate JDK Internals - OpenJDK
Summary. Strongly encapsulate all internal elements of the JDK, except for critical internal APIs such as sun. misc. Unsafe .
Read more >
JDK-8263547 JEP 403: Strongly Encapsulate JDK Internals
Is my understanding correct that by default ALL jdk packages will be closed by default after this JEP? If so, shouldn't that be...
Read more >
Upgrading to OkHttp 4 - Square Open Source
OkHttp 4.x upgrades our implementation language from Java to Kotlin and keeps everything else the same. We've chosen Kotlin because it gives us...
Read more >
Candidate JEP 403: Strongly Encapsulate JDK Internals [spoiler
Using kitty remote-control to open a new-window with my zsh config intact · add-apt-repository fails with file not found · Screwed up git ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found