Skip to content

Commit

Permalink
SNOW-1063844: Add missing braces to condition and loop bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz committed Feb 21, 2024
1 parent 08e7889 commit 6884e0d
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 46 deletions.
16 changes: 12 additions & 4 deletions src/main/java/net/snowflake/client/config/SFClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ public void setConfigFilePath(String configFilePath) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SFClientConfig that = (SFClientConfig) o;
return Objects.equals(commonProps, that.commonProps);
}
Expand Down Expand Up @@ -78,8 +82,12 @@ public void setLogPath(String logPath) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CommonProps that = (CommonProps) o;
return Objects.equals(logLevel, that.logLevel) && Objects.equals(logPath, that.logPath);
}
Expand Down
72 changes: 54 additions & 18 deletions src/main/java/net/snowflake/client/core/ExecTimeTelemetryData.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,92 +48,128 @@ public ExecTimeTelemetryData() {
}

public void setBindStart() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.bindStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setOCSPStatus(Boolean ocspEnabled) {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.ocspEnabled = ocspEnabled;
}

public void setBindEnd() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.bindEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setHttpClientStart() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.httpClientStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setHttpClientEnd() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.httpClientEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setGzipStart() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.gzipStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setGzipEnd() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.gzipEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setQueryEnd() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.queryEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setQueryId(String queryId) {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.queryId = queryId;
}

public void setProcessResultChunkStart() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.processResultChunkStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setProcessResultChunkEnd() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.processResultChunkEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setResponseIOStreamStart() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.responseIOStreamStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setResponseIOStreamEnd() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.responseIOStreamEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setCreateResultSetStart() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.createResultSetStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void setCreateResultSetEnd() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.createResultSetEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
}

public void incrementRetryCount() {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.retryCount++;
}

public void setRequestId(String requestId) {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
this.requestId = requestId;
}

public void addRetryLocation(String location) {
if (!this.sendData) return;
if (!this.sendData) {
return;
}
if (Strings.isNullOrEmpty(this.retryLocations)) {
this.retryLocations = location;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ public QueryContextDTO serializeQueryContextDTO() {
logCacheEntries();

TreeSet<QueryContextElement> elements = getElements();
if (elements.size() == 0) return null;
if (elements.size() == 0) {
return null;
}

try {
QueryContextDTO queryContextDTO = new QueryContextDTO();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/snowflake/client/core/ResultUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,9 @@ public static long calculateUpdateCount(SFBaseResultSet resultSet)
|| statementType == SFStatementType.MERGE
|| statementType == SFStatementType.MULTI_INSERT) {
int columnCount = resultSet.getMetaData().getColumnCount();
for (int i = 0; i < columnCount; i++)
for (int i = 0; i < columnCount; i++) {
updateCount += resultSet.getLong(i + 1); // add up number of rows updated
}
} else {
updateCount = 0;
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,11 @@ public synchronized void open() throws SFException, SnowflakeSQLException {
"Query context cache is {}", ((disableQueryContextCache) ? "disabled" : "enabled"));

// Initialize QCC
if (!disableQueryContextCache) qcc = new QueryContextCache(this.getQueryContextCacheSize());
else qcc = null;
if (!disableQueryContextCache) {
qcc = new QueryContextCache(this.getQueryContextCacheSize());
} else {
qcc = null;
}

// start heartbeat for this session so that the master token will not expire
startHeartbeatForThisSession();
Expand Down Expand Up @@ -814,7 +817,9 @@ public void close() throws SFException, SnowflakeSQLException {
getClientInfo().clear();

// qcc can be null, if disabled.
if (qcc != null) qcc.clearCache();
if (qcc != null) {
qcc.clearCache();
}

isClosed = true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/snowflake/client/core/SessionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,11 @@ private static SFLoginOutput newSession(
// Fix for HikariCP refresh token issue:SNOW-533673.
// If token value is not set but password field is set then
// the driver treats password as token.
if (loginInput.getToken() != null)
if (loginInput.getToken() != null) {
data.put(ClientAuthnParameter.TOKEN.name(), loginInput.getToken());
else data.put(ClientAuthnParameter.TOKEN.name(), loginInput.getPassword());
} else {
data.put(ClientAuthnParameter.TOKEN.name(), loginInput.getPassword());
}

} else if (authenticatorType == ClientAuthnDTO.AuthenticatorType.SNOWFLAKE_JWT) {
data.put(ClientAuthnParameter.AUTHENTICATOR.name(), authenticatorType.name());
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/snowflake/client/core/UUIDUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ private static UUID UUIDImpl() {

long msb = 0;
long lsb = 0;
for (int i = 0; i < 8; i++) msb = (msb << 8) | (randomBytes[i] & 0xff);
for (int i = 8; i < 16; i++) lsb = (lsb << 8) | (randomBytes[i] & 0xff);
for (int i = 0; i < 8; i++) {
msb = (msb << 8) | (randomBytes[i] & 0xff);
}
for (int i = 8; i < 16; i++) {
lsb = (lsb << 8) | (randomBytes[i] & 0xff);
}

return new UUID(msb, lsb);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,14 @@ VariableTypeArray executeBatchInternalWithArrayBind(boolean isLong) throws SQLEx
if (updateCount == batchSize) {
if (isLong) {
updateCounts = new VariableTypeArray(null, new long[updateCount]);
for (int idx = 0; idx < updateCount; idx++) updateCounts.longArr[idx] = 1;
for (int idx = 0; idx < updateCount; idx++) {
updateCounts.longArr[idx] = 1;
}
} else {
updateCounts = new VariableTypeArray(new int[updateCount], null);
for (int idx = 0; idx < updateCount; idx++) updateCounts.intArr[idx] = 1;
for (int idx = 0; idx < updateCount; idx++) {
updateCounts.intArr[idx] = 1;
}
}
} else {
if (isLong) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ public void upload(
blob.uploadMetadata(null, transferOptions, opContext);

// close any open streams in the "toClose" list and return
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
for (FileInputStream is : toClose) {
IOUtils.closeQuietly(is);
}

return;
} catch (Exception ex) {
Expand Down Expand Up @@ -566,7 +568,9 @@ public void upload(

} while (retryCount <= getMaxRetries());

for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
for (FileInputStream is : toClose) {
IOUtils.closeQuietly(is);
}

throw new SnowflakeSQLException(
queryId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,9 @@ public void upload(
logger.debug("Upload successful", false);

// close any open streams in the "toClose" list and return
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
for (FileInputStream is : toClose) {
IOUtils.closeQuietly(is);
}

return;
}
Expand All @@ -716,7 +718,9 @@ public void upload(
logger.debug("Upload successful", false);

// close any open streams in the "toClose" list and return
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
for (FileInputStream is : toClose) {
IOUtils.closeQuietly(is);
}

return;
} catch (Exception ex) {
Expand Down Expand Up @@ -747,7 +751,9 @@ public void upload(

} while (retryCount <= getMaxRetries());

for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
for (FileInputStream is : toClose) {
IOUtils.closeQuietly(is);
}

throw new SnowflakeSQLLoggedException(
queryId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ public ExecutorService newExecutor() {
myUpload.waitForCompletion();

// get out
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
for (FileInputStream is : toClose) {
IOUtils.closeQuietly(is);
}
return;
} catch (Exception ex) {

Expand Down Expand Up @@ -610,7 +612,9 @@ public ExecutorService newExecutor() {
}
} while (retryCount <= getMaxRetries());

for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
for (FileInputStream is : toClose) {
IOUtils.closeQuietly(is);
}

throw new SnowflakeSQLLoggedException(
queryId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ public void testGetTablesRaceCondition()
}));
}
executorService.shutdown();
for (int i = 0; i < 10; i++) futures.get(i).get();
for (int i = 0; i < 10; i++) {
futures.get(i).get();
}
}
}
}
4 changes: 3 additions & 1 deletion src/test/java/net/snowflake/client/jdbc/HeartbeatIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ public void testSuccess() throws Exception {
}));
}
executorService.shutdown();
for (int idx = 0; idx < concurrency; idx++) futures.get(idx).get();
for (int idx = 0; idx < concurrency; idx++) {
futures.get(idx).get();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,7 @@ public void testResultChunkDownloaderException() throws SQLException {
try {
// Normally this step won't cause too long. Because we will get exception once trying to get
// result from the first chunk downloader
while (resultSet.next())
;
while (resultSet.next()) {}
fail("Should not reach here. Last next() command is supposed to throw an exception");
} catch (SnowflakeSQLException ex) {
// pass, do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1801,14 +1801,18 @@ public void testBind() throws Throwable {
+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
+ " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

for (int idx = 0; idx < 16; idx++) addBindBatch(preparedStatement, sqlDate);
for (int idx = 0; idx < 16; idx++) {
addBindBatch(preparedStatement, sqlDate);
}

updateCounts = preparedStatement.executeBatch();

// GS optimizes this into one insert execution
assertEquals("Number of update counts", 16, updateCounts.length);

for (int idx = 0; idx < 16; idx++) assertEquals("update count", 1, updateCounts[idx]);
for (int idx = 0; idx < 16; idx++) {
assertEquals("update count", 1, updateCounts[idx]);
}
} finally {
if (regularStatement != null) {
regularStatement.execute("DROP TABLE testBind");
Expand Down

0 comments on commit 6884e0d

Please sign in to comment.