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

Remove scheme from URI before fetching path for CRL path check #2622

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

Conversation

Jeffery-Wasty
Copy link
Contributor

When attempting to get the Path for use in Configurable Retry Logic patch check, this could fail if the scheme was not file. This is resolved by removing the scheme component from the URI before feeding it into Paths.get().

@Jeffery-Wasty Jeffery-Wasty added this to the 12.10.0 milestone Feb 28, 2025
@Jeffery-Wasty Jeffery-Wasty self-assigned this Feb 28, 2025
Copilot

This comment was marked as resolved.

Choose a reason for hiding this comment

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

PR Overview

This PR refactors the logic for obtaining a usable file path for CRL path checks by removing the URI scheme from the path before calling Paths.get(). It introduces a more robust way to handle file URIs and adds an appropriate error message for invalid paths.

  • Extracts the scheme-specific part from the URI and removes its leading "/" before verifying if the path is a directory.
  • Adds handling for InvalidPathException with a corresponding error message update in SQLServerResource.java.

Reviewed Changes

File Description
src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java Modifies the retrieval of the code source URI to remove the scheme component and adjusts path handling accordingly.
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java Adds an error message for invalid paths.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java:296

  • Ensure that schemeSpecificPart is non-empty and starts with '/' before removing the first character to avoid unexpected behavior or exceptions.
schemeSpecificPart = schemeSpecificPart.substring(1); // Remove leading /

src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java:301

  • [nitpick] Consider extracting the hardcoded string 'target/classes/' into a constant to improve maintainability and clarity.
location = location.substring(0, location.length() - ("target/classes/").length());

Choose a reason for hiding this comment

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

PR Overview

This PR fixes an issue where a URI scheme interferes with fetching the file path for the CRL path check by stripping the scheme before using Paths.get().

  • Remove the URI scheme using getSchemeSpecificPart and a new constant for the forward slash.
  • Update error handling and add a new resource error message for invalid paths.

Reviewed Changes

File Description
src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java Adjusts path extraction from the CodeSource URI by removing the scheme and handling directory checks
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java Adds a new error message resource for invalid path exceptions

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java:298

  • Removing the leading '/' may yield an incorrect relative path on Unix-based systems where an absolute path is required. Consider verifying that this transformation works correctly on all target platforms.
schemeSpecificPart = schemeSpecificPart.substring(1); // Remove leading /
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 45.45455% with 6 lines in your changes missing coverage. Please review.

Project coverage is 51.52%. Comparing base (7e795d4) to head (72f15af).

Files with missing lines Patch % Lines
...crosoft/sqlserver/jdbc/ConfigurableRetryLogic.java 45.45% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2622      +/-   ##
============================================
- Coverage     51.54%   51.52%   -0.02%     
- Complexity     3996     4003       +7     
============================================
  Files           147      147              
  Lines         33694    33702       +8     
  Branches       5630     5631       +1     
============================================
  Hits          17366    17366              
- Misses        13877    13905      +28     
+ Partials       2451     2431      -20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Jeffery-Wasty
Copy link
Contributor Author

Passes tests with run id = 110147.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

WildFly server won't start using code after the 12.9.0 preview due to error with ConfigurableRetryLogic
1 participant