【发布时间】:2016-07-18 09:35:09
【问题描述】:
我有以下代码行,sonarqube 说,
“更改此条件,使其不会总是评估为假”
。
下面是线。
if (params.isEmpty() && params == null) {
throw new ServiceSDKException("Parameters cannot be empty or null!");
}
以下是整个方法,以备不时之需。
public void init(String params) throws ServiceSDKException {
if (params.isEmpty() && params == null) {
throw new ServiceSDKException("Parameters cannot be empty or null!");
}
String[] configParams = params.split(",");
options.setMqttURL(configParams[0]);
options.setMqttClientID(configParams[1]);
try {
options.setWillMessage("v1/items/mqtt/0/event/will"
, "Last will"
, 2, true);
new File("./db").mkdir();
edgeNode = EdgeNodeFactory.createMQTTChannel("./db", options,
subscriptionTask, 500, 500);
isClientConnected = true;
} catch (EdgeNodeException e) {
isClientConnected = false;
throw new ServiceSDKException("EdgeNodeException occurred", e);
}
}
【问题讨论】:
-
如果 params 为 null,您将收到 NullPointerException。您应该首先检查 null ,然后使用 or 操作( || )检查 isEmpty()
-
什么都不是
""和null。因此,条件永远无法评估为真。
标签: java null sonarqube conditional sonarqube-5.0