Skip to content

Use class's class loader when looking up HttpClient factory.#10232

Merged
diemol merged 2 commits intoSeleniumHQ:trunkfrom
dennisoelkers:fix/use-class-classloader-for-factory-lookup
Jan 8, 2022
Merged

Use class's class loader when looking up HttpClient factory.#10232
diemol merged 2 commits intoSeleniumHQ:trunkfrom
dennisoelkers:fix/use-class-classloader-for-factory-lookup

Conversation

@dennisoelkers
Copy link
Copy Markdown
Contributor

Description

Motivation and Context

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.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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`.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 7, 2022

CLA assistant check
All committers have signed the CLA.

@dennisoelkers dennisoelkers changed the title Use class' class loader when looking up HttpClient factory. Use class's class loader when looking up HttpClient factory. Jan 7, 2022
@titusfortner titusfortner added the C-java Java Bindings label Jan 8, 2022
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jan 8, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Copy Markdown
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution, @dennisoelkers!

@diemol diemol merged commit 7463406 into SeleniumHQ:trunk Jan 8, 2022
@dennisoelkers dennisoelkers deleted the fix/use-class-classloader-for-factory-lookup branch January 10, 2022 08:50
elgatov pushed a commit to elgatov/selenium that referenced this pull request Jun 27, 2022
…umHQ#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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-java Java Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants