-
Notifications
You must be signed in to change notification settings - Fork 733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Illegal Reflective Access Operation to field java.net.HttpURLConnection.method #754
Comments
This is not an exception, as you noted your action succeeded. Unfortunately, this can't be directly fixed. If you use the JDK version of If you switch to another implementation such as OkHttp3, this should go away. Also, if you use Java 8 you will not see this warning. "All illegal access operations will be denied in a future release", but as of Java 13 that has not happened yet. |
I experience the same behavior using kotlin with repository.setDefaultBranch("some-branch")
I experience the same with Java 14 ( jvm target set in build.gradle.kts: |
@lotharschulz |
Yes and wasn't successful so far. I use GitHub.connect to connect to GitHub.com with Environmental variables. The code in OkHttpConnectorTest was promising in the beginning, but I could not find a hint that made my code work. In case it exists, please point me to an example that explains how to use |
How about something like this: import okhttp3.OkHttpClient;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;
import org.kohsuke.github.extras.okhttp3.OkHttpConnector;
// ... in some class
static OkHttpClient baseClient = new OkHttpClient();
// ... in some method
GitHub gitHub = GitHubBuilder.
.fromEnvironment()
.withConnector(new OkHttpConnector(baseClient.newBuilder().build())
.build(); |
Thanks @bitwiseman! These are the relevant kotlin changes I was able to do based on your input: additional dependency using kotlin dsl (build.gradle.kts) implementation("com.squareup.okhttp3:okhttp:4.9.0") some kt file import okhttp3.OkHttpClient
import org.kohsuke.github.GitHubBuilder.fromEnvironment
import org.kohsuke.github.extras.okhttp3.OkHttpConnector
...
// within an existing class
companion object {
private val baseClient = OkHttpClient()
}
...
// within an existing fun
fromEnvironment().
withConnector(
OkHttpConnector(baseClient)
).build() |
I just hit the same issue when updating a the state of a Milestone.
As previously stated running the code in Java 8 does not produce the warning. Moving to OkHttp is not an option (at least not for me). The OpenFeign project has the same issue with their default HttpClient (inability to support more HTTP verbs such as PATCH). They did not use reflection to fix this. Instead they offer other Http clients such as Apache HTTP Client. Would it be possible for this project to provide another HttpConnector based on Apache Http Client? |
@aalmiray As an alternative it looks like you can allow reflective access in various ways: https://stackoverflow.com/questions/46454995/how-to-hide-warning-illegal-reflective-access-in-java-9-without-jvm-argument At some point we'll remove the dependency on |
I might actually, considering my tool has to run with Java 8 for a loooong time. Coincidentally, the links you posted don't work in this situation: running in classpath mode in Java 9+ The 1st link simply disables the warning. OK-ish in 9 - 15 but will break in 16+. Hence why an alternate client is needed. |
@aalmiray We might be able to avoid reflection by using |
Well I could use the header but hub4j would still use the reflective call to set the HTTP verb. I don't think there's a way from my POV as a consumer to tell if the header works or not. The real test is to remove the reflective call and use the override header. |
@aalmiray I meant, you could try updating hub4j to use the header and remove the reflective access. Replacing this insanity: github-api/src/main/java/org/kohsuke/github/GitHubHttpUrlConnectionClient.java Lines 165 to 189 in 7c8a7ff
|
@aalmiray If you could build this locally and give it try, that would a huge help. I will probably not include this in the next release, but the release after it (a few weeks from now) since this is in some respects a huge change. All this said, it would still be great if you wanted to implement a connector for Apache client - that client and okhttp3 offer a number of advanced features including response caching that radically improve performance and stability of this library. It would be nice to be able to give people Apache as an drop-in option similar to OkHttp3. |
Thank you @bitwiseman 😄 ! |
@bitwiseman I can confirm the override method works and no reflection calls occur. Thank you! |
Unfortunately, We're back to the original guidance: use another client library such as OkHttp. |
Any chance of this being revisited? Sadly OkHttp is not an option for me. Apache Client would be much better. Closing a milestone when running on JDK17 will trigger an error because of reflective access. |
@aalmiray are you sure? I think this has been fixed with the latest versions and the switch to the JDK11+ client. |
Yes, I'm sure as I can't use the JDK11+ client just yet. The code that applies |
Well, sure, if you’re not using the JDK 11 one, it will fail. I can understand the Okhttp client might not be ideal given you end up with Kotlin around but not sure why the JDK 11 client wouldn’t be. |
Correct. JReleaser's Maven and Gradle plugins are still bound to JDK8 for the foreseeable future. This problem becomes moot the project upgrades to JDK11. I suppose staying with hub4j 1.129 is the current workaround. |
Describe the bug
I attempt to archive a repository using the following code:
When checking GitHub itself, the repository is in fact archived, however I receive a warning in the stderr stream consisting of the following:
To Reproduce
Steps to reproduce the behavior:
GHRepository
that is not yet archived.archive()
on that repository.Expected behavior
I expect that there should not be any illegal reflective access exceptions.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: