Skip to content

Commit

Permalink
Cleanup of static code analysis findings
Browse files Browse the repository at this point in the history
Three AvoidCatchingNPE findings are pending in the class BoschHttpClient.
Could be false positive, because NullPointer exceptions appear during tests run.

Signed-off-by: Gerd Zanker <[email protected]>
  • Loading branch information
GerdZanker committed Mar 20, 2023
1 parent 02e3340 commit da883d9
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public BoschSHCDeviceHandler(Thing thing) {

@Override
public void initialize() {

var config = this.config = getConfigAs(BoschSHCConfiguration.class);

String deviceId = config.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ protected BoschSHCHandler(Thing thing) {
*/
@Override
public void initialize() {

// Initialize device services
try {
this.initializeServices();
Expand Down Expand Up @@ -304,7 +303,6 @@ protected <TService extends BoschSHCService<TState>, TState extends BoschSHCServ
protected <TService extends BoschSHCService<TState>, TState extends BoschSHCServiceState> void registerService(
TService service, Consumer<TState> stateUpdateListener, Collection<String> affectedChannels,
boolean shouldFetchInitialState) throws BoschSHCException {

String deviceId = verifyBoschID();
service.initialize(getBridgeHandler(), deviceId, stateUpdateListener);
this.registerService(service, affectedChannels);
Expand All @@ -325,7 +323,6 @@ protected <TService extends BoschSHCService<TState>, TState extends BoschSHCServ
*/
private <TService extends BoschSHCService<TState>, TState extends BoschSHCServiceState> void fetchInitialState(
TService service, Consumer<TState> stateUpdateListener) {

try {
@Nullable
TState serviceState = service.getState();
Expand Down Expand Up @@ -353,7 +350,6 @@ private <TService extends BoschSHCService<TState>, TState extends BoschSHCServic
*/
protected <TService extends AbstractBoschSHCService> void registerStatelessService(TService service)
throws BoschSHCException {

String deviceId = verifyBoschID();
service.initialize(getBridgeHandler(), deviceId);
// do not register in service list because the service can not receive state updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ protected BoschSHCSystemService(String serviceName, Class<TState> stateClass, St
@Override
public @Nullable TState getState()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {

BridgeHandler bridgeHandler = getBridgeHandler();
if (bridgeHandler == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ public BatteryLevelService() {
@Override
public @Nullable DeviceServiceData getState()
throws InterruptedException, TimeoutException, ExecutionException, BoschSHCException {

String deviceId = getDeviceId();
if (deviceId == null) {
return null;
}

BridgeHandler bridgeHandler = getBridgeHandler();
if (bridgeHandler == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public class BoschSHCServiceState {
/**
* gson instance to convert a class to json string and back.
*/
private static final Gson gson = new Gson();
private static final Gson GSON = new Gson();

private static final Logger logger = LoggerFactory.getLogger(BoschSHCServiceState.class);
/**
* Logger marked as transient to exclude the logger from JSON serialization.
*/
private final transient Logger logger = LoggerFactory.getLogger(BoschSHCServiceState.class);

/**
* State type. Initialized when instance is created.
Expand Down Expand Up @@ -67,7 +70,7 @@ protected boolean isValid() {

public static <TState extends BoschSHCServiceState> @Nullable TState fromJson(String json,
Class<TState> stateClass) {
var state = gson.fromJson(json, stateClass);
var state = GSON.fromJson(json, stateClass);
if (state == null || !state.isValid()) {
return null;
}
Expand All @@ -77,7 +80,7 @@ protected boolean isValid() {

public static <TState extends BoschSHCServiceState> @Nullable TState fromJson(JsonElement json,
Class<TState> stateClass) {
var state = gson.fromJson(json, stateClass);
var state = GSON.fromJson(json, stateClass);
if (state == null || !state.isValid()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public enum SmokeDetectorCheckState {
SMOKE_TEST_FAILED;

public static SmokeDetectorCheckState from(String stateString) {

try {
return SmokeDetectorCheckState.valueOf(stateString);
} catch (Exception a) {
Expand Down

0 comments on commit da883d9

Please sign in to comment.