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

Fix for broken mssql-jdbc.properties location logic #2579

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Jeffery-Wasty
Copy link
Contributor

The logic for finding the mssql-jdbc.properties file, used in Configurable Retry Logic was correct for test environments, and when building the driver manually, but not correct when using the driver as a jar or dependency. This fixes that issue by only removing the target/classes suffix if needed.

@Jeffery-Wasty Jeffery-Wasty modified the milestone: 12.10.0 Jan 9, 2025
@Jeffery-Wasty Jeffery-Wasty linked an issue Jan 9, 2025 that may be closed by this pull request
@Jeffery-Wasty Jeffery-Wasty self-assigned this Jan 9, 2025
@@ -283,16 +282,25 @@ private static void createConnectionRules(LinkedList<String> listOfRules) throws
private static String getCurrentClassPath() throws SQLServerException {
String location = "";
String className = "";
String locationSuffix = "target/classes/";
Copy link
Member

Choose a reason for hiding this comment

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

What about C:\target\classes\mssql-jdbc.jar + C:\target\classes\mssql-jdbc.properties?. Unlikely scenario I suppose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unlikely scenario that I'm not sure how we could address. In that case, they would not be able to use CRL with the props file. They would have to use the connection string property instead.

Comment on lines 288 to 289
className = new Object() {}.getClass().getEnclosingClass().getName();
location = Class.forName(className).getProtectionDomain().getCodeSource().getLocation().getPath();
Copy link
Member

Choose a reason for hiding this comment

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

If I do a java -jar mssql-jdbc.jar with the above code, the location always includes the JAR name eg. /path/to/mssql-jdbc.jar. But, when I run it in my IDE I get /path/to/. Without the JAR name in the path.

Do you need to account for the cases mentioned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Class.forName(className).getProtectionDomain().getCodeSource().getLocation().getPath(); will return the /path/to example you showed above, i.e. where the jar is without including the jar. This is the scenario I tested before pushing this PR.

// the above will return with a suffix "target/classes/" which must be removed, as, with the first case, the
// properties file should be in the main directory.

if (location.endsWith(locationSuffix)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to handle this case of testing/building the driver?

Would it be fair to expect developers to place the the mssql-jdbc.properties file under <path>/tagret/classes themselves while tresting/debugging etc. ?

Copy link

Choose a reason for hiding this comment

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

IDEs may normally put things there from resources subdirectory, so probably yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not that the properties file is in target/classes. It should be in the main directory, and the documentation says this (or it will when we update it for 12.10.0). Class.forName(className).getProtectionDomain().getCodeSource().getLocation().getPath(); returns the correct main directory when the driver is ran as a dependency or as a jar, when its ran while testing (i.e. running the source code for tests), the above snippet instead returns <main_directory>/target/classes which must be "corrected" to the main directory when the props file should be.

We can avoid this whole issue by only expected the props file in the main directory OR next to the jar, however this would mean we wouldn't be able to run internal testing for CRL using a props file. Also, since we're thinking of perhaps using the props file in the future for other connection properties, this would only be more of a limitation in the future.

Finally, I think this will be resolved when we institute custom locations for the props file as another connection string property (in our backlog). Where we only have to deal with "unusual" paths if they are specified in the prop.

@Jeffery-Wasty Jeffery-Wasty added the Under Review Used for pull requests under review label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Under Review Used for pull requests under review
Projects
Status: Under Peer Review
Development

Successfully merging this pull request may close these issues.

Broken logic in ConfigurableRetryLogic
4 participants