鱿鱼:S2259和Apache Commons

时间:2016-12-28 19:25:05

标签: sonarqube

请考虑以下代码:

private boolean hasEnabledBluetooth() {
    final BluetoothAdapter bluetoothAdapter = getBluetoothAdapter();
    Validate.notNull(bluetoothAdapter);
    return bluetoothAdapter.isEnabled();
}

最后一行return bluetoothAdapter.isEnabled();触发 squid:S2259 (在SonarQube 5.6.4 LTS中)

  

可能会抛出NullPointerException,因为'bluetoothAdapter'在这里可以为空

事实并非如此。 bluetoothAdapter在这里不可为空,因为如果情况如此,Apache公共Validate.notNull()将抛出异常。

这是一个已知问题吗?它会被修复吗?

更新

每个请求,完整的源代码(在同一个文件中):

private BluetoothAdapter getBluetoothAdapter() {
    final BluetoothManager bluetoothManager = getBluetoothManager();
    Validate.notNull(bluetoothManager);
    return bluetoothManager.getAdapter();
}

BluetoothManager getBluetoothManager() {
    return (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
}

0 个答案:

没有答案