Skip to content

Commit

Permalink
fix: add null value judgment
Browse files Browse the repository at this point in the history
  • Loading branch information
LUAgam committed Jul 10, 2023
1 parent 604b782 commit 09b6d6b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ private void checkRule(LinkedHashMap<String, String> row) {
String delayThresholdStr = row.get(COLUMN_DELAY_THRESHOLD);
String heartbeatTimeoutStr = row.get(COLUMN_HEARTBEAT_TIMEOUT);
String heartbeatRetryStr = row.get(COLUMN_HEARTBEAT_RETRY);
if (!StringUtil.isBlank(delayThresholdStr) && IntegerUtil.parseInt(delayThresholdStr) < -1) {
if (StringUtil.isBlank(delayThresholdStr) || IntegerUtil.parseInt(delayThresholdStr) < -1) {
throw new ConfigException("Column '" + COLUMN_DELAY_THRESHOLD + "' should be an integer greater than or equal to -1!");
}
if (!StringUtil.isBlank(heartbeatTimeoutStr) && IntegerUtil.parseInt(heartbeatTimeoutStr) < 0) {
if (StringUtil.isBlank(heartbeatTimeoutStr) || IntegerUtil.parseInt(heartbeatTimeoutStr) < 0) {
throw new ConfigException("Column '" + COLUMN_HEARTBEAT_TIMEOUT + "' should be an integer greater than or equal to 0!");
}
if (!StringUtil.isBlank(heartbeatRetryStr) && IntegerUtil.parseInt(heartbeatRetryStr) < 0) {
if (StringUtil.isBlank(heartbeatRetryStr) || IntegerUtil.parseInt(heartbeatRetryStr) < 0) {
throw new ConfigException("Column '" + COLUMN_HEARTBEAT_RETRY + "' should be an integer greater than or equal to 0!");
}
String heartbeatKeepAliveStr = row.get(COLUMN_KEEP_ALIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ private DBInstance transformRowToDBInstance(LinkedHashMap<String, String> map) {
DBInstance dbInstance = new DBInstance();
StringBuilder url = new StringBuilder();
List<Property> propertyList = Lists.newArrayList();
String key;
String entryValue;
for (Map.Entry<String, String> entry : map.entrySet()) {
switch (entry.getKey()) {
case COLUMN_NAME:
Expand Down Expand Up @@ -469,6 +471,13 @@ private DBInstance transformRowToDBInstance(LinkedHashMap<String, String> map) {
case COLUMN_TEST_ON_BORROW:
case COLUMN_TEST_ON_RETURN:
case COLUMN_TEST_WHILE_IDLE:
key = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, entry.getKey());
entryValue = entry.getValue();
if (StringUtil.isBlank(entryValue) || (!StringUtil.equalsIgnoreCase(entryValue, Boolean.FALSE.toString()) && !StringUtil.equalsIgnoreCase(entryValue, Boolean.TRUE.toString()))) {
throw new ConfigException("Column '" + entry.getKey() + "' values only support 'false' or 'true'.");
}
propertyList.add(new Property(entryValue, key));
break;
case COLUMN_CONNECTION_TIMEOUT:
case COLUMN_CONNECTION_HEARTBEAT_TIMEOUT:
case COLUMN_TIME_BETWEEN_EVICTION_RUNS_MILLIS:
Expand All @@ -477,8 +486,12 @@ private DBInstance transformRowToDBInstance(LinkedHashMap<String, String> map) {
case COLUMN_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS:
case COLUMN_FLOW_HIGH_LEVEL:
case COLUMN_FLOW_LOW_LEVEL:
String key = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, entry.getKey());
propertyList.add(new Property(entry.getValue(), key));
key = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, entry.getKey());
entryValue = entry.getValue();
if (StringUtil.isBlank(entryValue) || IntegerUtil.parseInt(entryValue) <= 0) {
throw new ConfigException("Column '" + entry.getKey() + "' should be an integer greater than 0!");
}
propertyList.add(new Property(entryValue, key));
break;
default:
break;
Expand Down

0 comments on commit 09b6d6b

Please sign in to comment.