未验证 提交 b82c8bca 编写于 作者: T Tocker 提交者: GitHub

Fix:Alibaba Coding Guidelines-Object的equals方法容易抛空指针异常,应使用常量或确定有值的对象来调用equals。 (#2919)

上级 576406a4
......@@ -282,7 +282,7 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>, Applic
PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(this.target.getClass());
for (PropertyDescriptor descriptor : descriptors) {
String name = descriptor.getName();
if (!name.equals("class")) {
if (!"class".equals(name)) {
RelaxedNames relaxedNames = RelaxedNames.forCamelCase(name);
if (prefixes == null) {
for (String relaxedName : relaxedNames) {
......
......@@ -78,7 +78,7 @@ public class JdbcTypeUtil {
public static Object typeConvert(String tableName ,String columnName, String value, int sqlType, String mysqlType) {
if (value == null
|| (value.equals("") && !(isText(mysqlType) || sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR))) {
|| ("".equals(value) && !(isText(mysqlType) || sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR))) {
return null;
}
......
......@@ -95,11 +95,11 @@ public class ESSyncService {
long begin = System.currentTimeMillis();
String type = dml.getType();
if (type != null && type.equalsIgnoreCase("INSERT")) {
if (type != null && "INSERT".equalsIgnoreCase(type)) {
insert(config, dml);
} else if (type != null && type.equalsIgnoreCase("UPDATE")) {
} else if (type != null && "UPDATE".equalsIgnoreCase(type)) {
update(config, dml);
} else if (type != null && type.equalsIgnoreCase("DELETE")) {
} else if (type != null && "DELETE".equalsIgnoreCase(type)) {
delete(config, dml);
} else {
return;
......
......@@ -312,7 +312,7 @@ public class MappingConfig implements AdapterConfig {
columnItem.setRowKey(true);
rowKeyColumn = columnItem;
} else {
if (field == null || field.equals("")) {
if (field == null || "".equals(field)) {
columnItem.setFamily(family);
columnItem.setQualifier(columnField.getKey());
} else {
......
......@@ -31,11 +31,11 @@ public class HbaseSyncService {
public void sync(MappingConfig config, Dml dml) {
if (config != null) {
String type = dml.getType();
if (type != null && type.equalsIgnoreCase("INSERT")) {
if (type != null && "INSERT".equalsIgnoreCase(type)) {
insert(config, dml);
} else if (type != null && type.equalsIgnoreCase("UPDATE")) {
} else if (type != null && "UPDATE".equalsIgnoreCase(type)) {
update(config, dml);
} else if (type != null && type.equalsIgnoreCase("DELETE")) {
} else if (type != null && "DELETE".equalsIgnoreCase(type)) {
delete(config, dml);
}
if (logger.isDebugEnabled()) {
......
......@@ -47,11 +47,11 @@ public class KuduSyncService {
public void sync(KuduMappingConfig config, Dml dml) {
if (config != null) {
String type = dml.getType();
if (type != null && type.equalsIgnoreCase("INSERT")) {
if (type != null && "INSERT".equalsIgnoreCase(type)) {
insert(config, dml);
} else if (type != null && type.equalsIgnoreCase("UPDATE")) {
} else if (type != null && "UPDATE".equalsIgnoreCase(type)) {
upsert(config, dml);
} else if (type != null && type.equalsIgnoreCase("DELETE")) {
} else if (type != null && "DELETE".equalsIgnoreCase(type)) {
delete(config, dml);
}
if (logger.isDebugEnabled()) {
......
......@@ -181,11 +181,11 @@ public class CommonRest {
*/
@PutMapping("/syncSwitch/{destination}/{status}")
public Result etl(@PathVariable String destination, @PathVariable String status) {
if (status.equals("on")) {
if ("on".equals(status)) {
syncSwitch.on(destination);
logger.info("#Destination: {} sync on", destination);
return Result.createSuccess("实例: " + destination + " 开启同步成功");
} else if (status.equals("off")) {
} else if ("off".equals(status)) {
syncSwitch.off(destination);
logger.info("#Destination: {} sync off", destination);
return Result.createSuccess("实例: " + destination + " 关闭同步成功");
......
......@@ -208,13 +208,13 @@ public class RdbSyncService {
if (config != null) {
try {
String type = dml.getType();
if (type != null && type.equalsIgnoreCase("INSERT")) {
if (type != null && "INSERT".equalsIgnoreCase(type)) {
insert(batchExecutor, config, dml);
} else if (type != null && type.equalsIgnoreCase("UPDATE")) {
} else if (type != null && "UPDATE".equalsIgnoreCase(type)) {
update(batchExecutor, config, dml);
} else if (type != null && type.equalsIgnoreCase("DELETE")) {
} else if (type != null && "DELETE".equalsIgnoreCase(type)) {
delete(batchExecutor, config, dml);
} else if (type != null && type.equalsIgnoreCase("TRUNCATE")) {
} else if (type != null && "TRUNCATE".equalsIgnoreCase(type)) {
truncate(batchExecutor, config);
}
if (logger.isDebugEnabled()) {
......
......@@ -71,7 +71,7 @@ public class SyncUtil {
if (value instanceof Boolean) {
pstmt.setBoolean(i, (Boolean) value);
} else if (value instanceof String) {
boolean v = !value.equals("0");
boolean v = !"0".equals(value);
pstmt.setBoolean(i, v);
} else if (value instanceof Number) {
boolean v = ((Number) value).intValue() != 0;
......
......@@ -49,7 +49,7 @@ public class MQMessageUtils {
int i = pkHashConfig.lastIndexOf(":");
if (i > 0) {
String pkStr = pkHashConfig.substring(i + 1);
if (pkStr.equalsIgnoreCase("$pk$")) {
if ("$pk$".equalsIgnoreCase(pkStr)) {
data.hashMode.autoPkHash = true;
} else {
data.hashMode.pkNames = Lists.newArrayList(StringUtils.split(pkStr,
......
......@@ -78,7 +78,7 @@ public class JdbcTypeUtil {
public static Object typeConvert(String tableName, String columnName, String value, int sqlType, String mysqlType) {
if (value == null
|| (value.equals("") && !(isText(mysqlType) || sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR))) {
|| ("".equals(value) && !(isText(mysqlType) || sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR))) {
return null;
}
......
......@@ -522,7 +522,7 @@ public class MysqlConnection implements ErosaConnection {
rs = query("select @@global.binlog_checksum");
List<String> columnValues = rs.getFieldValues();
if (columnValues != null && columnValues.size() >= 1 && columnValues.get(0) != null
&& columnValues.get(0).toUpperCase().equals("CRC32")) {
&& "CRC32".equals(columnValues.get(0).toUpperCase())) {
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_CRC32;
} else {
binlogChecksum = LogEvent.BINLOG_CHECKSUM_ALG_OFF;
......
......@@ -31,7 +31,7 @@ public class DescribeBackupPolicyRequest extends AbstractRequest<RdsBackupPolicy
JSONObject jsonObj = JSON.parseObject(result);
RdsBackupPolicy policy = new RdsBackupPolicy();
policy.setBackupRetentionPeriod(jsonObj.getString("BackupRetentionPeriod"));
policy.setBackupLog(jsonObj.getString("BackupLog").equalsIgnoreCase("Enable"));
policy.setBackupLog("Enable".equalsIgnoreCase(jsonObj.getString("BackupLog")));
policy.setLogBackupRetentionPeriod(jsonObj.getIntValue("LogBackupRetentionPeriod"));
policy.setPreferredBackupPeriod(jsonObj.getString("PreferredBackupPeriod"));
policy.setPreferredBackupTime(jsonObj.getString("PreferredBackupTime"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册