Skip to content

Commit

Permalink
SNOW-1063844: Force braces for condition and loop bodies (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz authored Feb 21, 2024
1 parent eab1c63 commit 9a1aefe
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 52 deletions.
5 changes: 3 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
SNOW-XXXXX

## Pre-review self checklist
- [ ] PR branch is updated with all the changes from `master` branch
- [ ] The code is correctly formatted (run `mvn -P check-style validate`)
- [ ] I don't expose unnecessary new public API (run `mvn verify` and inspect `target/japicmp/japicmp.html`)
- [ ] Pull request name is prefixed with `SNOW-XXXX: `
- [ ] New public API is not unnecessary exposed (run `mvn verify` and inspect `target/japicmp/japicmp.html`)
- [ ] The pull request name is prefixed with `SNOW-XXXX: `

## External contributors - please answer these questions before submitting a pull request. Thanks!

Expand Down
10 changes: 6 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ You may import the coding style from IntelliJ so that the coding style can be ap
- In the **File** -> **Settings/Plugins**, and install `google-java-format` plugin.
- Enable `google-java-format` for the JDBC project.
- In the source code window, select **Code** -> **Reformat** to apply the coding style.
- Additionally configure IDE to not use wildcard imports in **File** -> **Ecitor** -> **Code Style** -> **Java** set:
- **Use single class import**
- **Class count to use import with '*'** to 1000
- **Names count to use static import with '*'** to 1000
- Additionally configure IDE in **File** -> **Editor** -> **Code Style** -> **Java** to
- not use wildcard imports (tab **Imports**):
- **Use single class import**
- **Class count to use import with '*'** to 1000
- **Names count to use static import with '*'** to 1000
- always use braces in ``if/while/for/do..while`` in (tab **Wrapping and Braces**)

Tests
=====
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@
<module name="Checker">
<module name="TreeWalker">
<module name="AvoidStarImport"/>
<module name="NeedBraces"/>
</module>
</module>
</checkstyleRules>
Expand Down
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();
}
}
}
}
Loading

0 comments on commit 9a1aefe

Please sign in to comment.