Skip to content

Commit

Permalink
[SNOW-835640] Gracefully handle MessageFormat.format exceptions (#1420)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-skumbham authored Jun 14, 2023
1 parent f988341 commit c0e805b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/net/snowflake/client/log/JDK14Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ private void logInternal(Level level, String msg, boolean masked) {
private void logInternal(Level level, String msg, Object... arguments) {
if (jdkLogger.isLoggable(level)) {
String[] source = findSourceInStack();
String message = MessageFormat.format(refactorString(msg), evaluateLambdaArgs(arguments));
String message = "";
try {
message = MessageFormat.format(refactorString(msg), evaluateLambdaArgs(arguments));
} catch (IllegalArgumentException e) {
message = "Unable to format msg: " + msg;
}
jdkLogger.logp(level, source[0], source[1], SecretDetector.maskSecrets(message));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Properties;
import java.util.logging.Level;
import net.snowflake.client.AbstractDriverIT;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
Expand Down Expand Up @@ -70,4 +71,20 @@ public void testJDK14LoggingWithClientConfigPermissionError() throws IOException
Files.delete(configFilePath);
directory.delete();
}

@Test
public void testJDK14LoggerWithBracesInMessage() {
JDK14Logger logger = new JDK14Logger(JDK14LoggerWithClientLatestIT.class.getName());
JDK14Logger.setLevel(Level.FINE);
logger.debug("Returning column: 12: a: Group b) Hi {Hello World War} cant wait");
JDK14Logger.setLevel(Level.OFF);
}

@Test
public void testJDK14LoggerWithQuotesInMessage() {
JDK14Logger logger = new JDK14Logger(JDK14LoggerWithClientLatestIT.class.getName());
JDK14Logger.setLevel(Level.FINE);
logger.debug("Returning column: 12: a: Group b) Hi {Hello 'World' War} cant wait");
JDK14Logger.setLevel(Level.OFF);
}
}

0 comments on commit c0e805b

Please sign in to comment.