Skip to content

Commit 23c024b

Browse files
muskan124947Divang Sharma
authored andcommitted
Update readFromFile() in ConfigurableRetryLogic to handle filePath related issues (#2650)
* Addressed-Cannot use mssql-jdbc 12.10 on WildFly if WildFly directory path contains a space * Add general exception * Updated logging level
1 parent ae4dc32 commit 23c024b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ private static String getCurrentClassPath() throws SQLServerException {
336336
* if unable to read from the file
337337
*/
338338
private static LinkedList<String> readFromFile(String connectionStringProperty) throws SQLServerException {
339-
String filePath = getCurrentClassPath();
339+
String filePath = "";
340340
LinkedList<String> list = new LinkedList<>();
341-
342341
try {
342+
filePath = getCurrentClassPath();
343343
File f = new File(filePath);
344344
try (BufferedReader buffer = new BufferedReader(new FileReader(f))) {
345345
String readLine;
@@ -354,13 +354,22 @@ private static LinkedList<String> readFromFile(String connectionStringProperty)
354354
} catch (FileNotFoundException e) {
355355
// If the file is not found either A) We're not using CRL OR B) the path is wrong. Do not error out, instead
356356
// log a message.
357-
if (CONFIGURABLE_RETRY_LOGGER.isLoggable(java.util.logging.Level.FINER)) {
358-
CONFIGURABLE_RETRY_LOGGER.finest("File not found at path - \"" + filePath + "\"");
357+
if (CONFIGURABLE_RETRY_LOGGER.isLoggable(java.util.logging.Level.FINE)) {
358+
CONFIGURABLE_RETRY_LOGGER.fine("File not found at path - \"" + filePath + "\"");
359+
}
360+
} catch (InvalidPathException e) {
361+
if (CONFIGURABLE_RETRY_LOGGER.isLoggable(java.util.logging.Level.FINE)) {
362+
CONFIGURABLE_RETRY_LOGGER.fine("Invalid path specified - \"" + filePath + "\"");
359363
}
360364
} catch (IOException e) {
361365
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_errorReadingStream"));
362366
Object[] msgArgs = {e.getMessage() + ", from path - \"" + filePath + "\""};
363367
throw new SQLServerException(form.format(msgArgs), null, 0, e);
368+
} catch (Exception e) {
369+
// General exception handling
370+
if (CONFIGURABLE_RETRY_LOGGER.isLoggable(java.util.logging.Level.FINE)) {
371+
CONFIGURABLE_RETRY_LOGGER.fine("An unexpected error occurred while reading from file: " + e.getMessage());
372+
}
364373
}
365374
return list;
366375
}

0 commit comments

Comments
 (0)