Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.snowflake.client.config;

import static net.snowflake.client.jdbc.SnowflakeUtil.convertSystemGetEnvToBooleanValue;
import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;
import static net.snowflake.client.jdbc.SnowflakeUtil.isWindows;
import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetEnv;

import com.fasterxml.jackson.dataformat.toml.TomlMapper;
import com.google.common.base.Strings;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -162,7 +162,7 @@ private static String createUrl(Map<String, String> fileConnectionConfiguration)
logger.debug("Host created using parameters from connection configuration file: {}", host);
String port = fileConnectionConfiguration.get("port");
String protocol = fileConnectionConfiguration.get("protocol");
if (Strings.isNullOrEmpty(port)) {
if (isNullOrEmpty(port)) {
if ("https".equals(protocol)) {
port = "443";
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/net/snowflake/client/core/CredentialManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.snowflake.client.core;

import com.amazonaws.util.StringUtils;
import com.google.common.base.Strings;
import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;

import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
Expand Down Expand Up @@ -149,7 +149,7 @@ static void fillCachedDPoPBundledAccessToken(SFLoginInput loginInput) throws SFE
synchronized void fillCachedCredential(
SFLoginInput loginInput, String host, String username, CachedCredentialType credType)
throws SFException {
if (StringUtils.isNullOrEmpty(username)) {
if (isNullOrEmpty(username)) {
logger.debug("Missing username; Cannot read from credential cache");
return;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ synchronized void fillCachedCredential(

private void updateInputWithTokenAndPublicKey(String cred, SFLoginInput loginInput)
throws SFException {
if (Strings.isNullOrEmpty(cred)) {
if (isNullOrEmpty(cred)) {
String[] values = cred.split("\\.");
if (values.length != 2) {
throw new SFException(
Expand Down Expand Up @@ -313,11 +313,11 @@ static void writeDPoPBundledAccessToken(SFLoginInput loginInput) throws SFExcept
/** Store the temporary credential */
synchronized void writeTemporaryCredential(
String host, String user, String cred, CachedCredentialType credType) {
if (StringUtils.isNullOrEmpty(user)) {
if (isNullOrEmpty(user)) {
logger.debug("Missing username; Cannot write to credential cache");
return;
}
if (Strings.isNullOrEmpty(cred)) {
if (isNullOrEmpty(cred)) {
logger.debug("No {} is given.", credType);
return; // no credential
}
Expand Down Expand Up @@ -426,7 +426,7 @@ synchronized void deleteTemporaryCredential(
logMissingJnaJarForSecureLocalStorage();
return;
}
if (StringUtils.isNullOrEmpty(user)) {
if (isNullOrEmpty(user)) {
logger.debug("Missing username; Cannot delete from credential cache");
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.snowflake.client.core;

import com.google.common.base.Strings;
import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;

import net.minidev.json.JSONObject;
import net.snowflake.client.jdbc.telemetryOOB.TelemetryService;
import net.snowflake.client.util.TimeMeasurement;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void setRequestId(String requestId) {
}

public void addRetryLocation(String location) {
if (Strings.isNullOrEmpty(this.retryLocations)) {
if (isNullOrEmpty(this.retryLocations)) {
this.retryLocations = location;
} else {
this.retryLocations = this.retryLocations.concat(", ").concat(location);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/snowflake/client/core/FileUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.snowflake.client.core;

import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;
import static net.snowflake.client.jdbc.SnowflakeUtil.isWindows;

import com.google.common.base.Strings;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -190,7 +190,7 @@ static String getFileOwnerName(Path filePath) throws IOException {
}

private static String getContextStr(String context) {
return Strings.isNullOrEmpty(context) ? "" : context + ": ";
return isNullOrEmpty(context) ? "" : context + ": ";
}

public static boolean exists(File file) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.snowflake.client.core;

import com.google.common.base.Strings;
import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;

import java.io.Serializable;

/**
Expand Down Expand Up @@ -35,14 +36,14 @@ public HttpClientSettingsKey(
Boolean gzipDisabled) {
this.useProxy = true;
this.ocspMode = mode != null ? mode : OCSPMode.FAIL_OPEN;
this.proxyHost = !Strings.isNullOrEmpty(host) ? host.trim() : "";
this.proxyHost = !isNullOrEmpty(host) ? host.trim() : "";
this.proxyPort = port;
this.nonProxyHosts = !Strings.isNullOrEmpty(nonProxyHosts) ? nonProxyHosts.trim() : "";
this.proxyUser = !Strings.isNullOrEmpty(user) ? user.trim() : "";
this.proxyPassword = !Strings.isNullOrEmpty(password) ? password.trim() : "";
this.proxyProtocol = !Strings.isNullOrEmpty(scheme) ? scheme.trim() : "http";
this.nonProxyHosts = !isNullOrEmpty(nonProxyHosts) ? nonProxyHosts.trim() : "";
this.proxyUser = !isNullOrEmpty(user) ? user.trim() : "";
this.proxyPassword = !isNullOrEmpty(password) ? password.trim() : "";
this.proxyProtocol = !isNullOrEmpty(scheme) ? scheme.trim() : "http";
this.gzipDisabled = gzipDisabled;
this.userAgentSuffix = !Strings.isNullOrEmpty(userAgentSuffix) ? userAgentSuffix.trim() : "";
this.userAgentSuffix = !isNullOrEmpty(userAgentSuffix) ? userAgentSuffix.trim() : "";
}

public HttpClientSettingsKey(OCSPMode mode) {
Expand All @@ -52,7 +53,7 @@ public HttpClientSettingsKey(OCSPMode mode) {

HttpClientSettingsKey(OCSPMode mode, String userAgentSuffix, Boolean gzipDisabled) {
this(mode);
this.userAgentSuffix = !Strings.isNullOrEmpty(userAgentSuffix) ? userAgentSuffix.trim() : "";
this.userAgentSuffix = !isNullOrEmpty(userAgentSuffix) ? userAgentSuffix.trim() : "";
this.gzipDisabled = gzipDisabled;
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/snowflake/client/core/HttpUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.snowflake.client.core;

import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;
import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetProperty;
import static org.apache.http.client.config.CookieSpecs.DEFAULT;
import static org.apache.http.client.config.CookieSpecs.IGNORE_COOKIES;
Expand All @@ -8,7 +9,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.microsoft.azure.storage.OperationContext;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -403,8 +403,7 @@ public static CloseableHttpClient buildHttpClient(
key.getProxyHttpProtocol(),
key.getNonProxyHosts()));
httpClientBuilder.setProxy(proxy).setRoutePlanner(sdkProxyRoutePlanner);
if (!Strings.isNullOrEmpty(key.getProxyUser())
&& !Strings.isNullOrEmpty(key.getProxyPassword())) {
if (!isNullOrEmpty(key.getProxyUser()) && !isNullOrEmpty(key.getProxyPassword())) {
Credentials credentials =
new UsernamePasswordCredentials(key.getProxyUser(), key.getProxyPassword());
AuthScope authScope = new AuthScope(key.getProxyHost(), key.getProxyPort());
Expand Down Expand Up @@ -966,7 +965,7 @@ private static String executeRequestInternal(

private static void checkForDPoPNonceError(HttpResponse response) throws IOException {
String errorResponse = EntityUtils.toString(response.getEntity());
if (!Strings.isNullOrEmpty(errorResponse)) {
if (!isNullOrEmpty(errorResponse)) {
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
JsonNode rootNode = objectMapper.readTree(errorResponse);
JsonNode errorNode = rootNode.get(ERROR_FIELD_NAME);
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/net/snowflake/client/core/SFBaseSession.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.snowflake.client.core;

import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;
import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetEnv;
import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetProperty;

import com.google.common.base.Strings;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -593,27 +593,27 @@ public HttpClientSettingsKey getHttpClientKey() throws SnowflakeSQLException {
userAgentSuffix,
gzipDisabled);
// There are 2 possible parameters for non proxy hosts that can be combined into 1
String combinedNonProxyHosts = Strings.isNullOrEmpty(nonProxyHosts) ? "" : nonProxyHosts;
if (!Strings.isNullOrEmpty(noProxy)) {
String combinedNonProxyHosts = isNullOrEmpty(nonProxyHosts) ? "" : nonProxyHosts;
if (!isNullOrEmpty(noProxy)) {
combinedNonProxyHosts += combinedNonProxyHosts.length() == 0 ? "" : "|";
combinedNonProxyHosts += noProxy;
}

// It is possible that a user can have both http and https proxies specified in the JVM
// parameters. The default protocol is http.
String proxyProtocol = "http";
if (!Strings.isNullOrEmpty(httpProxyProtocol)) {
if (!isNullOrEmpty(httpProxyProtocol)) {
proxyProtocol = httpProxyProtocol;
} else if (!Strings.isNullOrEmpty(httpsProxyHost)
&& !Strings.isNullOrEmpty(httpsProxyPort)
&& Strings.isNullOrEmpty(httpProxyHost)
&& Strings.isNullOrEmpty(httpProxyPort)) {
} else if (!isNullOrEmpty(httpsProxyHost)
&& !isNullOrEmpty(httpsProxyPort)
&& isNullOrEmpty(httpProxyHost)
&& isNullOrEmpty(httpProxyPort)) {
proxyProtocol = "https";
}

if (proxyProtocol.equals("https")
&& !Strings.isNullOrEmpty(httpsProxyHost)
&& !Strings.isNullOrEmpty(httpsProxyPort)) {
&& !isNullOrEmpty(httpsProxyHost)
&& !isNullOrEmpty(httpsProxyPort)) {
logger.debug("Using https proxy configuration from JVM parameters");
int proxyPort;
try {
Expand All @@ -635,8 +635,8 @@ public HttpClientSettingsKey getHttpClientKey() throws SnowflakeSQLException {
gzipDisabled);
logHttpClientInitInfo(ocspAndProxyAndGzipKey);
} else if (proxyProtocol.equals("http")
&& !Strings.isNullOrEmpty(httpProxyHost)
&& !Strings.isNullOrEmpty(httpProxyPort)) {
&& !isNullOrEmpty(httpProxyHost)
&& !isNullOrEmpty(httpProxyPort)) {
logger.debug("Using http proxy configuration from JVM parameters");
int proxyPort;
try {
Expand Down Expand Up @@ -703,10 +703,10 @@ private void logHttpClientInitInfo(HttpClientSettingsKey key) {
public void unsetInvalidProxyHostAndPort() {
// If proxyHost and proxyPort are used without http or https unset them, so they are not used
// later by the ProxySelector.
if (!Strings.isNullOrEmpty(systemGetProperty("proxyHost"))) {
if (!isNullOrEmpty(systemGetProperty("proxyHost"))) {
System.clearProperty("proxyHost");
}
if (!Strings.isNullOrEmpty(systemGetProperty("proxyPort"))) {
if (!isNullOrEmpty(systemGetProperty("proxyPort"))) {
System.clearProperty("proxyPort");
}
}
Expand Down Expand Up @@ -1145,7 +1145,7 @@ public String getDatabase() {
}

public void setDatabase(String database) {
if (!Strings.isNullOrEmpty(database)) {
if (!isNullOrEmpty(database)) {
this.database = database;
}
}
Expand All @@ -1155,7 +1155,7 @@ public String getSchema() {
}

public void setSchema(String schema) {
if (!Strings.isNullOrEmpty(schema)) {
if (!isNullOrEmpty(schema)) {
this.schema = schema;
}
}
Expand All @@ -1173,7 +1173,7 @@ public String getWarehouse() {
}

public void setWarehouse(String warehouse) {
if (!Strings.isNullOrEmpty(warehouse)) {
if (!isNullOrEmpty(warehouse)) {
this.warehouse = warehouse;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import static net.snowflake.client.core.QueryStatus.isAnError;
import static net.snowflake.client.core.QueryStatus.isStillRunning;
import static net.snowflake.client.core.SFLoginInput.getBooleanValue;
import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import java.security.PrivateKey;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
Expand Down Expand Up @@ -326,7 +326,7 @@ else if (isAnError(result)) {
// if an error message has been provided, set appropriate error message.
// This should override the default error message displayed when there is
// an error with no code.
if (!Strings.isNullOrEmpty(errorMessage) && !errorMessage.equalsIgnoreCase("null")) {
if (!isNullOrEmpty(errorMessage) && !errorMessage.equalsIgnoreCase("null")) {
result.setErrorMessage(errorMessage);
} else {
result.setErrorMessage("No error reported");
Expand Down Expand Up @@ -875,7 +875,7 @@ boolean isExternalbrowserOrOAuthFullFlowAuthenticator() {
boolean isOKTAAuthenticator() {
Map<SFSessionProperty, Object> connectionPropertiesMap = getConnectionPropertiesMap();
String authenticator = (String) connectionPropertiesMap.get(SFSessionProperty.AUTHENTICATOR);
return !Strings.isNullOrEmpty(authenticator) && authenticator.startsWith("https://");
return !isNullOrEmpty(authenticator) && authenticator.startsWith("https://");
}

/**
Expand Down Expand Up @@ -1040,7 +1040,7 @@ public Void call() throws SQLException {

/** Start heartbeat for this session */
protected void startHeartbeatForThisSession() {
if (getEnableHeartbeat() && !Strings.isNullOrEmpty(masterToken)) {
if (getEnableHeartbeat() && !isNullOrEmpty(masterToken)) {
logger.debug(
"Session {} start heartbeat, master token validity: {} s",
getSessionId(),
Expand All @@ -1055,7 +1055,7 @@ protected void startHeartbeatForThisSession() {

/** Stop heartbeat for this session */
protected void stopHeartbeatForThisSession() {
if (getEnableHeartbeat() && !Strings.isNullOrEmpty(masterToken)) {
if (getEnableHeartbeat() && !isNullOrEmpty(masterToken)) {
logger.debug("Session {} stop heartbeat", getSessionId());

HeartbeatBackground.getInstance().removeSession(this);
Expand Down Expand Up @@ -1298,12 +1298,12 @@ private void performSanityCheckOnProperties() throws SFException {
|| isUsernamePasswordMFAAuthenticator()) {
// userName and password are expected for both Snowflake and Okta.
String userName = (String) connectionPropertiesMap.get(SFSessionProperty.USER);
if (Strings.isNullOrEmpty(userName)) {
if (isNullOrEmpty(userName)) {
throw new SFException(ErrorCode.MISSING_USERNAME);
}

String password = (String) connectionPropertiesMap.get(SFSessionProperty.PASSWORD);
if (Strings.isNullOrEmpty(password)) {
if (isNullOrEmpty(password)) {

throw new SFException(ErrorCode.MISSING_PASSWORD);
}
Expand Down Expand Up @@ -1335,13 +1335,13 @@ public List<DriverPropertyInfo> checkProperties() {
if (isSnowflakeAuthenticator() || isOKTAAuthenticator()) {
// userName and password are expected for both Snowflake and Okta.
String userName = (String) connectionPropertiesMap.get(SFSessionProperty.USER);
if (Strings.isNullOrEmpty(userName)) {
if (isNullOrEmpty(userName)) {
missingProperties.add(
addNewDriverProperty(SFSessionProperty.USER.getPropertyKey(), "username for account"));
}

String password = (String) connectionPropertiesMap.get(SFSessionProperty.PASSWORD);
if (Strings.isNullOrEmpty(password)) {
if (isNullOrEmpty(password)) {
missingProperties.add(
addNewDriverProperty(
SFSessionProperty.PASSWORD.getPropertyKey(), "password for " + "account"));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/snowflake/client/core/SFTrustManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.snowflake.client.core;

import static net.snowflake.client.jdbc.SnowflakeUtil.isNullOrEmpty;
import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetEnv;
import static net.snowflake.client.jdbc.SnowflakeUtil.systemGetProperty;

Expand All @@ -10,7 +11,6 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Strings;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -577,8 +577,8 @@ private static CloseableHttpClient getHttpClient(int timeout) {
Protocol.HTTP,
proxySettingsKey.getNonProxyHosts());
httpClientBuilder = httpClientBuilder.setProxy(proxy).setRoutePlanner(sdkProxyRoutePlanner);
if (!Strings.isNullOrEmpty(proxySettingsKey.getProxyUser())
&& !Strings.isNullOrEmpty(proxySettingsKey.getProxyPassword())) {
if (!isNullOrEmpty(proxySettingsKey.getProxyUser())
&& !isNullOrEmpty(proxySettingsKey.getProxyPassword())) {
Credentials credentials =
new UsernamePasswordCredentials(
proxySettingsKey.getProxyUser(), proxySettingsKey.getProxyPassword());
Expand Down Expand Up @@ -1106,7 +1106,7 @@ private OCSPResp fetchOcspResponse(
String urlEncodedOCSPReq = URLUtil.urlEncode(ocspReqDerBase64);
if (SF_OCSP_RESPONSE_CACHE_SERVER_RETRY_URL_PATTERN != null) {
URL ocspUrl = new URL(ocspUrlStr);
if (!Strings.isNullOrEmpty(ocspUrl.getPath())) {
if (!isNullOrEmpty(ocspUrl.getPath())) {
path = ocspUrl.getPath();
}
if (ocspUrl.getPort() > 0) {
Expand Down
Loading
Loading