Skip to content
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

Load real driver class before use #31

Merged
merged 4 commits into from
Nov 17, 2022
Merged

Conversation

CadenP
Copy link
Contributor

@CadenP CadenP commented Nov 3, 2019

Issue #, if available: #26

Description of changes:
Load the real driver before it is used by calling Class.forName(this.realDriverClass). This ensures that the real driver has an opportunity to be registered.

If the real driver class does not exist, an IllegalStateException is thrown. This exception matches the assertThrows tested by AWSSecretsManagerDriverTest.test_getWrappedDriver_throws_badDriver.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Add loadRealDriver method to load the class indicated by realDriverClass.
Throw IllegalStateException if the class does not exist.
@CadenP
Copy link
Contributor Author

CadenP commented Nov 3, 2019

I am using this change on a project which uses AWSSecretsManagerPostgreSQLDriver with the default org.postgresql.Driver and can confirm it worked, at least in my environment.

Note that I have not tested it with any other drivers. However, the tests run as part of the install script all passed.

Copy link

@zhaidw zhaidw left a comment

Choose a reason for hiding this comment

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

main branch already has called getDefaultDriverClass(); in Line 195 of AWSSecretsManagerDriver.java

@CadenP
Copy link
Contributor Author

CadenP commented Feb 25, 2021

main branch already has called getDefaultDriverClass(); in Line 195 of AWSSecretsManagerDriver.java

Yep! And the addition in this pull request makes use of this knowledge, and that the result of that call is put into this.realDriverClass, and so calls Class.forName with it.

getDefaultDriverClass() does not call Class.forName, except for some variant of the MySQL driver. Other than that one exception it just returns a string, and does not do anything to ensure that the driver has been registered.

It's been a while since I created this pull request, and my mind has been elsewhere since. If I miss something simple, let me know! Also, I am no longer working on the project in which I came across this issue, so I will be unable to test any changes within that context.

Copy link

@tuannguyent20 tuannguyent20 left a comment

Choose a reason for hiding this comment

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

One year later... confirm this commit resolve my same issue today.

@simonmarty simonmarty added the bug Something isn't working label May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants