-
-
Notifications
You must be signed in to change notification settings - Fork 10
[JENKINS-75556] Fix ClassCastException and ClassNotFoundException in client builder #78
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
Conversation
|
Thanks very much! |
| .proxyBuilder(apiProxyClass) | ||
| .build().target(url); | ||
|
|
||
| // workaround for https://github.com/orgs/resteasy/discussions/4538 when using ResteasyWebTarget#proxyBuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had run into this bug with my testing of the plugin as well. Did you take a look into this solution on the jenkins docs for class loading issues? https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/#context-class-loaders
I was able to get this builder to work using the code below. Your implementation has the upside of being much simpler to follow, but I wasn't sure if it came with any other considerations to consider.
Thread t = Thread.currentThread();
ClassLoader orig = t.getContextClassLoader();
t.setContextClassLoader(apiProxyClass.getClassLoader());
try {
GiteeApiProxy apiProxy = ((ResteasyWebTarget) builder
// ... builder functions
.build().target(url))
.proxyBuilder(apiProxyClass)
.classloader(t.getContextClassLoader())
.build();
return new ResteasyGiteeClient(url, apiProxy, pullRequestIdProvider);
} finally {
t.setContextClassLoader(orig);
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Puffy1215 have you tested the implementation in this pull request? I'm more interested in delivering a fix that works than in changing implementation from one form to another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Puffy1215 Yeah, I tried a similar approach as you describe at first but did not really like fiddeling with the classloader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, I was interested in the thought process. I am perfectly comfortable with your solution as it is easier to understand.
I have tried your fixes and have found no issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried your fixes and have found no issues.
That is great news. I will merge and release this pull request.
|
|
||
| private GiteeClient buildClient(String url, String apiToken, ProxyConfiguration httpProxyConfig, boolean ignoreCertificateErrors, int connectionTimeout, int readTimeout) { | ||
| ResteasyClientBuilder builder = (ResteasyClientBuilder) ClientBuilder.newBuilder(); | ||
| ResteasyClientBuilder builder = new ResteasyClientBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this class? I cant find any reference to getHttpEngine being used in the codebase, and it is marked as deprecated. In either case it is confusing here that our private static class shares the name with the abstract class ResteasyClientBuilder.
I think it would be better if we renamed this class (ResteasyClientBuilderWithHttpCreds?), or moved the functionality to a private function. Open to thoughts. Perhaps this could be a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can just assume that it had its justification before #69. There was a large upgrade to resteasy and the justification could just have vanished by migrating the codebase to a newver version.
I'd recommend following that up in a separate PR in order to deliver a fix as #78 (comment) already points out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I can open an issue with this. I'll need to investigate some older commits but I believe the deprecated function has not been used, even previously, for a long time.
Follow-up for #69 that fixes https://issues.jenkins.io/browse/JENKINS-75556
@MarkEWaite this makes #77 obsolete
Testing done
Manually verified
Test connectionin System Configuration works as expected.Submitter checklist