Skip to content

Commit 7463406

Browse files
Use class' class loader when looking up HttpClient factory. (#10232)
Prior to this change, `HttpClient.Factory.create` was using `ServiceLoader.load` without passing in a class loader explicitly. In this case, `ServiceLoader` is using the current thread's default class loader to resolve the specified class name's service. In projects with a plugin system, this can lead to problems, when selenium dependencies are part of a jar file that is not on the class path the application was started with. For these projects, using selenium results in a `ClassNotFoundException` when the first remote call is performed. To fix this, using the class loader of the factory interface would be beneficial. In projects without a plugin architecture, it will mostly be identical with the class loader of the current thread, in other cases there is very high chance that the service which is to be loaded can be resolved through the class loader of `HttpClient.Factory`.
1 parent 3ef95ef commit 7463406

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎java/src/org/openqa/selenium/remote/http/HttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ interface Factory {
4848
* @throws IllegalStateException if more than one implementation with the given name can be found
4949
*/
5050
static Factory create(String name) {
51-
ServiceLoader<HttpClient.Factory> loader = ServiceLoader.load(HttpClient.Factory.class);
51+
ServiceLoader<HttpClient.Factory> loader = ServiceLoader.load(HttpClient.Factory.class, HttpClient.Factory.class.getClassLoader());
5252
Set<Factory> factories = StreamSupport.stream(loader.spliterator(), true)
5353
.filter(p -> p.getClass().isAnnotationPresent(HttpClientName.class))
5454
.filter(p -> name.equals(p.getClass().getAnnotation(HttpClientName.class).value()))

0 commit comments

Comments
 (0)