Skip to content

Commit 19de5b1

Browse files
authored
Fix some sonar smell
1 parent 877c1c0 commit 19de5b1

File tree

20 files changed

+63
-55
lines changed

20 files changed

+63
-55
lines changed

iotdb-client/cli/src/main/java/org/apache/iotdb/tool/backup/IoTDBDataBackTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ private static Properties getProperties(String configName) {
897897
LOGGER.info("Start to read config file {}", url);
898898
properties.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
899899
} catch (Exception e) {
900-
e.printStackTrace();
900+
LOGGER.error("Read config file {} error", url, e);
901901
}
902902
}
903903
return properties;
@@ -1079,7 +1079,7 @@ public static void propertiesFileUpdate(String filePath, String key, String newV
10791079
fileOutputStream.close();
10801080

10811081
} catch (IOException e) {
1082-
e.printStackTrace();
1082+
LOGGER.error("properties file update error.", e);
10831083
}
10841084
}
10851085

iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,10 @@ public void setCatalog(String arg0) throws SQLException {
280280
}
281281
}
282282

283-
Statement stmt = this.createStatement();
284-
String sql = "USE " + arg0;
285-
boolean rs;
283+
PreparedStatement stmt = this.prepareStatement("USE ?");
284+
stmt.setString(1, arg0);
286285
try {
287-
rs = stmt.execute(sql);
286+
stmt.execute();
288287
} catch (SQLException e) {
289288
stmt.close();
290289
logger.error("Use database error: {}", e.getMessage());
@@ -352,11 +351,10 @@ public void setSchema(String arg0) throws SQLException {
352351
}
353352
}
354353

355-
Statement stmt = this.createStatement();
356-
String sql = "USE " + arg0;
357-
boolean rs;
354+
PreparedStatement stmt = this.prepareStatement("USE ?");
355+
stmt.setString(1, arg0);
358356
try {
359-
rs = stmt.execute(sql);
357+
stmt.execute();
360358
} catch (SQLException e) {
361359
stmt.close();
362360
logger.error("Use database error: {}", e.getMessage());

iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,6 @@ public void setObject(int parameterIndex, Object parameterObj, int targetSqlType
456456
} else if ("false".equalsIgnoreCase((String) parameterObj)
457457
|| "N".equalsIgnoreCase((String) parameterObj)) {
458458
setBoolean(parameterIndex, false);
459-
} else if (((String) parameterObj).matches("-?\\d+\\.?\\d*")) {
460-
setBoolean(parameterIndex, !((String) parameterObj).matches("-?[0]+[.]*[0]*"));
461459
} else {
462460
throw new SQLException(
463461
"No conversion from " + parameterObj + " to Types.BOOLEAN possible.");

iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,7 +3227,7 @@ private void updateTSInsertTabletsReq(
32273227
request.addToSizeList(tablet.getRowSize());
32283228
}
32293229

3230-
// sample some records and judge weather need to add too many null values to convert to tablet.
3230+
// sample some records and judge whether need to add too many null values to convert to tablet.
32313231
private boolean judgeConvertOfOneDevice(List<List<String>> measurementsList) {
32323232
int size = measurementsList.size();
32333233
int sampleNum = (int) (size * SAMPLE_PROPORTION);

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@
3333
import org.apache.iotdb.consensus.ConsensusFactory;
3434
import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
3535

36+
import org.slf4j.Logger;
37+
import org.slf4j.LoggerFactory;
38+
3639
import java.io.File;
3740
import java.lang.reflect.Field;
3841
import java.util.Arrays;
3942

4043
public class ConfigNodeConfig {
4144

45+
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigNodeConfig.class);
46+
4247
/** ClusterName, the default value "defaultCluster" will be changed after join cluster. */
4348
private volatile String clusterName = "defaultCluster";
4449

@@ -1185,7 +1190,7 @@ public String getConfigMessage() {
11851190
.append(configContent)
11861191
.append(";");
11871192
} catch (Exception e) {
1188-
e.printStackTrace();
1193+
LOGGER.warn("Failed to get field {}", configField, e);
11891194
}
11901195
}
11911196
return configMessage.toString();

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/PartitionBalancer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
import org.slf4j.Logger;
4141
import org.slf4j.LoggerFactory;
4242

43+
import java.security.SecureRandom;
4344
import java.util.ArrayList;
4445
import java.util.Comparator;
4546
import java.util.HashMap;
4647
import java.util.List;
4748
import java.util.Map;
48-
import java.util.Random;
4949
import java.util.TreeMap;
5050
import java.util.concurrent.ConcurrentHashMap;
5151

@@ -274,7 +274,7 @@ private void shuffleAllocationStrategy(
274274
List<TTimePartitionSlot> timePartitionSlots,
275275
BalanceTreeMap<TConsensusGroupId, Integer> availableDataRegionGroupCounter,
276276
SeriesPartitionTable seriesPartitionTable) {
277-
final Random random = new Random();
277+
final SecureRandom random = new SecureRandom();
278278
List<TConsensusGroupId> availableDataRegionGroups =
279279
new ArrayList<>(availableDataRegionGroupCounter.keySet());
280280
for (TTimePartitionSlot timePartitionSlot : timePartitionSlots) {

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyCopySetRegionGroupAllocator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
2525
import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
2626

27+
import java.security.SecureRandom;
2728
import java.util.ArrayList;
2829
import java.util.Arrays;
2930
import java.util.Collections;
3031
import java.util.Comparator;
3132
import java.util.HashMap;
3233
import java.util.List;
3334
import java.util.Map;
34-
import java.util.Random;
3535
import java.util.Set;
3636
import java.util.stream.Collectors;
3737

@@ -40,7 +40,7 @@
4040
/** Allocate Region through Greedy and CopySet Algorithm. */
4141
public class GreedyCopySetRegionGroupAllocator implements IRegionGroupAllocator {
4242

43-
private static final Random RANDOM = new Random();
43+
private static final SecureRandom RANDOM = new SecureRandom();
4444
private static final int GCR_MAX_OPTIMAL_PLAN_NUM = 10;
4545

4646
private int replicationFactor;

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyRegionGroupAllocator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
2525
import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
2626

27+
import java.security.SecureRandom;
2728
import java.util.ArrayList;
2829
import java.util.HashMap;
2930
import java.util.List;
3031
import java.util.Map;
31-
import java.util.Random;
3232
import java.util.stream.Collectors;
3333

3434
/** Allocate Region Greedily */
3535
public class GreedyRegionGroupAllocator implements IRegionGroupAllocator {
3636

37-
public static final Random RANDOM = new Random();
37+
public static final SecureRandom RANDOM = new SecureRandom();
3838

3939
public GreedyRegionGroupAllocator() {
4040
// Empty constructor

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/TemplateTable.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,8 @@ private void serialize(OutputStream outputStream) throws IOException {
185185
}
186186
}
187187

188-
private void serializeTemplate(Template template, OutputStream outputStream) {
189-
try {
190-
template.serialize(outputStream);
191-
} catch (IOException e) {
192-
e.printStackTrace();
193-
}
188+
private void serializeTemplate(Template template, OutputStream outputStream) throws IOException {
189+
template.serialize(outputStream);
194190
}
195191

196192
private void deserialize(InputStream inputStream) throws IOException {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3444,7 +3444,7 @@ public String getConfigMessage() {
34443444
.append(configContent)
34453445
.append(";");
34463446
} catch (Exception e) {
3447-
e.printStackTrace();
3447+
logger.warn("Failed to get field {}", configField, e);
34483448
}
34493449
}
34503450
return configMessage.toString();

0 commit comments

Comments
 (0)