Skip to content

Commit 9a1aefe

Browse files
SNOW-1063844: Force braces for condition and loop bodies (#1645)
1 parent eab1c63 commit 9a1aefe

18 files changed

+139
-52
lines changed

.github/pull_request_template.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
SNOW-XXXXX
44

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

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

README.rst

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

159161
Tests
160162
=====

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@
595595
<module name="Checker">
596596
<module name="TreeWalker">
597597
<module name="AvoidStarImport"/>
598+
<module name="NeedBraces"/>
598599
</module>
599600
</module>
600601
</checkstyleRules>

src/main/java/net/snowflake/client/config/SFClientConfig.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ public void setConfigFilePath(String configFilePath) {
3535

3636
@Override
3737
public boolean equals(Object o) {
38-
if (this == o) return true;
39-
if (o == null || getClass() != o.getClass()) return false;
38+
if (this == o) {
39+
return true;
40+
}
41+
if (o == null || getClass() != o.getClass()) {
42+
return false;
43+
}
4044
SFClientConfig that = (SFClientConfig) o;
4145
return Objects.equals(commonProps, that.commonProps);
4246
}
@@ -78,8 +82,12 @@ public void setLogPath(String logPath) {
7882

7983
@Override
8084
public boolean equals(Object o) {
81-
if (this == o) return true;
82-
if (o == null || getClass() != o.getClass()) return false;
85+
if (this == o) {
86+
return true;
87+
}
88+
if (o == null || getClass() != o.getClass()) {
89+
return false;
90+
}
8391
CommonProps that = (CommonProps) o;
8492
return Objects.equals(logLevel, that.logLevel) && Objects.equals(logPath, that.logPath);
8593
}

src/main/java/net/snowflake/client/core/ExecTimeTelemetryData.java

+54-18
Original file line numberDiff line numberDiff line change
@@ -48,92 +48,128 @@ public ExecTimeTelemetryData() {
4848
}
4949

5050
public void setBindStart() {
51-
if (!this.sendData) return;
51+
if (!this.sendData) {
52+
return;
53+
}
5254
this.bindStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
5355
}
5456

5557
public void setOCSPStatus(Boolean ocspEnabled) {
56-
if (!this.sendData) return;
58+
if (!this.sendData) {
59+
return;
60+
}
5761
this.ocspEnabled = ocspEnabled;
5862
}
5963

6064
public void setBindEnd() {
61-
if (!this.sendData) return;
65+
if (!this.sendData) {
66+
return;
67+
}
6268
this.bindEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
6369
}
6470

6571
public void setHttpClientStart() {
66-
if (!this.sendData) return;
72+
if (!this.sendData) {
73+
return;
74+
}
6775
this.httpClientStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
6876
}
6977

7078
public void setHttpClientEnd() {
71-
if (!this.sendData) return;
79+
if (!this.sendData) {
80+
return;
81+
}
7282
this.httpClientEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
7383
}
7484

7585
public void setGzipStart() {
76-
if (!this.sendData) return;
86+
if (!this.sendData) {
87+
return;
88+
}
7789
this.gzipStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
7890
}
7991

8092
public void setGzipEnd() {
81-
if (!this.sendData) return;
93+
if (!this.sendData) {
94+
return;
95+
}
8296
this.gzipEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
8397
}
8498

8599
public void setQueryEnd() {
86-
if (!this.sendData) return;
100+
if (!this.sendData) {
101+
return;
102+
}
87103
this.queryEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
88104
}
89105

90106
public void setQueryId(String queryId) {
91-
if (!this.sendData) return;
107+
if (!this.sendData) {
108+
return;
109+
}
92110
this.queryId = queryId;
93111
}
94112

95113
public void setProcessResultChunkStart() {
96-
if (!this.sendData) return;
114+
if (!this.sendData) {
115+
return;
116+
}
97117
this.processResultChunkStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
98118
}
99119

100120
public void setProcessResultChunkEnd() {
101-
if (!this.sendData) return;
121+
if (!this.sendData) {
122+
return;
123+
}
102124
this.processResultChunkEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
103125
}
104126

105127
public void setResponseIOStreamStart() {
106-
if (!this.sendData) return;
128+
if (!this.sendData) {
129+
return;
130+
}
107131
this.responseIOStreamStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
108132
}
109133

110134
public void setResponseIOStreamEnd() {
111-
if (!this.sendData) return;
135+
if (!this.sendData) {
136+
return;
137+
}
112138
this.responseIOStreamEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
113139
}
114140

115141
public void setCreateResultSetStart() {
116-
if (!this.sendData) return;
142+
if (!this.sendData) {
143+
return;
144+
}
117145
this.createResultSetStart = SnowflakeUtil.getEpochTimeInMicroSeconds();
118146
}
119147

120148
public void setCreateResultSetEnd() {
121-
if (!this.sendData) return;
149+
if (!this.sendData) {
150+
return;
151+
}
122152
this.createResultSetEnd = SnowflakeUtil.getEpochTimeInMicroSeconds();
123153
}
124154

125155
public void incrementRetryCount() {
126-
if (!this.sendData) return;
156+
if (!this.sendData) {
157+
return;
158+
}
127159
this.retryCount++;
128160
}
129161

130162
public void setRequestId(String requestId) {
131-
if (!this.sendData) return;
163+
if (!this.sendData) {
164+
return;
165+
}
132166
this.requestId = requestId;
133167
}
134168

135169
public void addRetryLocation(String location) {
136-
if (!this.sendData) return;
170+
if (!this.sendData) {
171+
return;
172+
}
137173
if (Strings.isNullOrEmpty(this.retryLocations)) {
138174
this.retryLocations = location;
139175
} else {

src/main/java/net/snowflake/client/core/QueryContextCache.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ public QueryContextDTO serializeQueryContextDTO() {
340340
logCacheEntries();
341341

342342
TreeSet<QueryContextElement> elements = getElements();
343-
if (elements.size() == 0) return null;
343+
if (elements.size() == 0) {
344+
return null;
345+
}
344346

345347
try {
346348
QueryContextDTO queryContextDTO = new QueryContextDTO();

src/main/java/net/snowflake/client/core/ResultUtil.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,9 @@ public static long calculateUpdateCount(SFBaseResultSet resultSet)
411411
|| statementType == SFStatementType.MERGE
412412
|| statementType == SFStatementType.MULTI_INSERT) {
413413
int columnCount = resultSet.getMetaData().getColumnCount();
414-
for (int i = 0; i < columnCount; i++)
414+
for (int i = 0; i < columnCount; i++) {
415415
updateCount += resultSet.getLong(i + 1); // add up number of rows updated
416+
}
416417
} else {
417418
updateCount = 0;
418419
}

src/main/java/net/snowflake/client/core/SFSession.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,11 @@ public synchronized void open() throws SFException, SnowflakeSQLException {
683683
"Query context cache is {}", ((disableQueryContextCache) ? "disabled" : "enabled"));
684684

685685
// Initialize QCC
686-
if (!disableQueryContextCache) qcc = new QueryContextCache(this.getQueryContextCacheSize());
687-
else qcc = null;
686+
if (!disableQueryContextCache) {
687+
qcc = new QueryContextCache(this.getQueryContextCacheSize());
688+
} else {
689+
qcc = null;
690+
}
688691

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

816819
// qcc can be null, if disabled.
817-
if (qcc != null) qcc.clearCache();
820+
if (qcc != null) {
821+
qcc.clearCache();
822+
}
818823

819824
isClosed = true;
820825
}

src/main/java/net/snowflake/client/core/SessionUtil.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,11 @@ private static SFLoginOutput newSession(
475475
// Fix for HikariCP refresh token issue:SNOW-533673.
476476
// If token value is not set but password field is set then
477477
// the driver treats password as token.
478-
if (loginInput.getToken() != null)
478+
if (loginInput.getToken() != null) {
479479
data.put(ClientAuthnParameter.TOKEN.name(), loginInput.getToken());
480-
else data.put(ClientAuthnParameter.TOKEN.name(), loginInput.getPassword());
480+
} else {
481+
data.put(ClientAuthnParameter.TOKEN.name(), loginInput.getPassword());
482+
}
481483

482484
} else if (authenticatorType == ClientAuthnDTO.AuthenticatorType.SNOWFLAKE_JWT) {
483485
data.put(ClientAuthnParameter.AUTHENTICATOR.name(), authenticatorType.name());

src/main/java/net/snowflake/client/core/UUIDUtils.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ private static UUID UUIDImpl() {
2424

2525
long msb = 0;
2626
long lsb = 0;
27-
for (int i = 0; i < 8; i++) msb = (msb << 8) | (randomBytes[i] & 0xff);
28-
for (int i = 8; i < 16; i++) lsb = (lsb << 8) | (randomBytes[i] & 0xff);
27+
for (int i = 0; i < 8; i++) {
28+
msb = (msb << 8) | (randomBytes[i] & 0xff);
29+
}
30+
for (int i = 8; i < 16; i++) {
31+
lsb = (lsb << 8) | (randomBytes[i] & 0xff);
32+
}
2933

3034
return new UUID(msb, lsb);
3135
}

src/main/java/net/snowflake/client/jdbc/SnowflakePreparedStatementV1.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,14 @@ VariableTypeArray executeBatchInternalWithArrayBind(boolean isLong) throws SQLEx
903903
if (updateCount == batchSize) {
904904
if (isLong) {
905905
updateCounts = new VariableTypeArray(null, new long[updateCount]);
906-
for (int idx = 0; idx < updateCount; idx++) updateCounts.longArr[idx] = 1;
906+
for (int idx = 0; idx < updateCount; idx++) {
907+
updateCounts.longArr[idx] = 1;
908+
}
907909
} else {
908910
updateCounts = new VariableTypeArray(new int[updateCount], null);
909-
for (int idx = 0; idx < updateCount; idx++) updateCounts.intArr[idx] = 1;
911+
for (int idx = 0; idx < updateCount; idx++) {
912+
updateCounts.intArr[idx] = 1;
913+
}
910914
}
911915
} else {
912916
if (isLong) {

src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeAzureClient.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ public void upload(
536536
blob.uploadMetadata(null, transferOptions, opContext);
537537

538538
// close any open streams in the "toClose" list and return
539-
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
539+
for (FileInputStream is : toClose) {
540+
IOUtils.closeQuietly(is);
541+
}
540542

541543
return;
542544
} catch (Exception ex) {
@@ -566,7 +568,9 @@ public void upload(
566568

567569
} while (retryCount <= getMaxRetries());
568570

569-
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
571+
for (FileInputStream is : toClose) {
572+
IOUtils.closeQuietly(is);
573+
}
570574

571575
throw new SnowflakeSQLException(
572576
queryId,

src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeGCSClient.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,9 @@ public void upload(
694694
logger.debug("Upload successful", false);
695695

696696
// close any open streams in the "toClose" list and return
697-
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
697+
for (FileInputStream is : toClose) {
698+
IOUtils.closeQuietly(is);
699+
}
698700

699701
return;
700702
}
@@ -716,7 +718,9 @@ public void upload(
716718
logger.debug("Upload successful", false);
717719

718720
// close any open streams in the "toClose" list and return
719-
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
721+
for (FileInputStream is : toClose) {
722+
IOUtils.closeQuietly(is);
723+
}
720724

721725
return;
722726
} catch (Exception ex) {
@@ -747,7 +751,9 @@ public void upload(
747751

748752
} while (retryCount <= getMaxRetries());
749753

750-
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
754+
for (FileInputStream is : toClose) {
755+
IOUtils.closeQuietly(is);
756+
}
751757

752758
throw new SnowflakeSQLLoggedException(
753759
queryId,

src/main/java/net/snowflake/client/jdbc/cloud/storage/SnowflakeS3Client.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ public ExecutorService newExecutor() {
578578
myUpload.waitForCompletion();
579579

580580
// get out
581-
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
581+
for (FileInputStream is : toClose) {
582+
IOUtils.closeQuietly(is);
583+
}
582584
return;
583585
} catch (Exception ex) {
584586

@@ -610,7 +612,9 @@ public ExecutorService newExecutor() {
610612
}
611613
} while (retryCount <= getMaxRetries());
612614

613-
for (FileInputStream is : toClose) IOUtils.closeQuietly(is);
615+
for (FileInputStream is : toClose) {
616+
IOUtils.closeQuietly(is);
617+
}
614618

615619
throw new SnowflakeSQLLoggedException(
616620
queryId,

src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataInternalLatestIT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ public void testGetTablesRaceCondition()
268268
}));
269269
}
270270
executorService.shutdown();
271-
for (int i = 0; i < 10; i++) futures.get(i).get();
271+
for (int i = 0; i < 10; i++) {
272+
futures.get(i).get();
273+
}
272274
}
273275
}
274276
}

0 commit comments

Comments
 (0)