Skip to content

Commit 414d7a8

Browse files
[knx] Reduce compiler warnings (#12518)
added NonNullByDefault annotations rename functions and local variables not matching the naming scheme Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
1 parent 9b7478c commit 414d7a8

19 files changed

Lines changed: 96 additions & 65 deletions

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/KNXBindingConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Set;
1919
import java.util.stream.Stream;
2020

21+
import org.eclipse.jdt.annotation.NonNullByDefault;
2122
import org.openhab.core.thing.ThingTypeUID;
2223

2324
/**
@@ -26,6 +27,7 @@
2627
*
2728
* @author Karel Goderis - Initial contribution
2829
*/
30+
@NonNullByDefault
2931
public class KNXBindingConstants {
3032

3133
public static final String BINDING_ID = "knx";

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/KNXTypeMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
import org.openhab.core.types.Type;
1818

1919
import tuwien.auto.calimero.datapoint.Datapoint;
20-
import tuwien.auto.calimero.process.ProcessEvent;
2120

2221
/**
2322
* This interface must be implemented by classes that provide a type mapping
2423
* between openHAB and KNX.
2524
* When a command or status update is sent to an item on the openHAB event bus,
2625
* it must be clear, in which format it must be sent to KNX and vice versa.
2726
*
28-
* @author Kai Kreuzer
27+
* @author Kai Kreuzer - Initial contribution
2928
*
3029
*/
3130
@NonNullByDefault
@@ -45,7 +44,8 @@ public interface KNXTypeMapper {
4544
* maps a datapoint value to an openHAB command or state
4645
*
4746
* @param datapoint the source datapoint
48-
* @param data the datapoint value as an ASDU byte array (see <code>{@link ProcessEvent}.getASDU()</code>)
47+
* @param data the datapoint value as an ASDU byte array (see
48+
* <code>{@link tuwien.auto.calimero.process.ProcessEvent}.getASDU()</code>)
4949
* @return a command or state of openHAB
5050
*/
5151
@Nullable

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/AbstractSpec.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import org.eclipse.jdt.annotation.NonNullByDefault;
1616
import org.eclipse.jdt.annotation.Nullable;
17-
import org.openhab.binding.knx.internal.client.InboundSpec;
18-
import org.openhab.binding.knx.internal.client.OutboundSpec;
1917

2018
import tuwien.auto.calimero.GroupAddress;
2119
import tuwien.auto.calimero.KNXFormatException;
@@ -57,7 +55,8 @@ protected final GroupAddress toGroupAddress(GroupAddressConfiguration ga) {
5755
/**
5856
* Return the data point type.
5957
* <p>
60-
* See {@link InboundSpec#getDPT()} and {@link OutboundSpec#getDPT()}.
58+
* See {@link org.openhab.binding.knx.internal.client.InboundSpec#getDPT()} and
59+
* {@link org.openhab.binding.knx.internal.client.OutboundSpec#getDPT()}.
6160
*
6261
* @return the data point type.
6362
*/

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/channel/ListenSpecImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Collections;
1818
import java.util.List;
1919

20+
import org.eclipse.jdt.annotation.NonNullByDefault;
2021
import org.eclipse.jdt.annotation.Nullable;
2122
import org.openhab.binding.knx.internal.client.InboundSpec;
2223

@@ -28,6 +29,7 @@
2829
* @author Simon Kaufmann - initial contribution and API.
2930
*
3031
*/
32+
@NonNullByDefault
3133
public class ListenSpecImpl extends AbstractSpec implements InboundSpec {
3234

3335
private final List<GroupAddress> listenAddresses;

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/AbstractKNXClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private void releaseConnection() {
244244
});
245245
}
246246

247-
private <T> T nullify(T target, @Nullable Consumer<T> lastWill) {
247+
private <T> @Nullable T nullify(T target, @Nullable Consumer<T> lastWill) {
248248
if (target != null && lastWill != null) {
249249
lastWill.accept(target);
250250
}
@@ -392,7 +392,8 @@ public final boolean unregisterGroupAddressListener(GroupAddressListener listene
392392

393393
@Override
394394
public boolean isConnected() {
395-
return link != null && link.isOpen();
395+
final var tmpLink = link;
396+
return tmpLink != null && tmpLink.isOpen();
396397
}
397398

398399
@Override

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/CustomKNXNetworkLinkIP.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package org.openhab.binding.knx.internal.client;
1414

15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
1517
import tuwien.auto.calimero.KNXException;
1618
import tuwien.auto.calimero.knxnetip.KNXnetIPConnection;
1719
import tuwien.auto.calimero.link.KNXNetworkLinkIP;
@@ -24,6 +26,7 @@
2426
* @author Simon Kaufmann - initial contribution and API
2527
*
2628
*/
29+
@NonNullByDefault
2730
public class CustomKNXNetworkLinkIP extends KNXNetworkLinkIP {
2831

2932
public static final int TUNNELING = KNXNetworkLinkIP.TUNNELING;

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/DeviceInspector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private Map<String, String> readDeviceProperties(IndividualAddress address) {
100100
OPERATION_TIMEOUT);
101101
if ((elements == null ? 0 : toUnsigned(elements)) == 1) {
102102
Thread.sleep(OPERATION_INTERVAL);
103-
String ManufacturerID = Manufacturer.getName(toUnsigned(getClient().readDeviceProperties(address,
103+
String manufacturerID = Manufacturer.getName(toUnsigned(getClient().readDeviceProperties(address,
104104
DEVICE_OBJECT, PID.MANUFACTURER_ID, 1, 1, false, OPERATION_TIMEOUT)));
105105
Thread.sleep(OPERATION_INTERVAL);
106106
String serialNo = toHex(getClient().readDeviceProperties(address, DEVICE_OBJECT, PID.SERIAL_NUMBER, 1,
@@ -112,7 +112,7 @@ private Map<String, String> readDeviceProperties(IndividualAddress address) {
112112
String firmwareRevision = Integer.toString(toUnsigned(getClient().readDeviceProperties(address,
113113
DEVICE_OBJECT, PID.FIRMWARE_REVISION, 1, 1, false, OPERATION_TIMEOUT)));
114114

115-
ret.put(MANUFACTURER_NAME, ManufacturerID);
115+
ret.put(MANUFACTURER_NAME, manufacturerID);
116116
if (serialNo != null) {
117117
ret.put(MANUFACTURER_SERIAL_NO, serialNo);
118118
}
@@ -121,7 +121,7 @@ private Map<String, String> readDeviceProperties(IndividualAddress address) {
121121
}
122122
ret.put(MANUFACTURER_FIRMWARE_REVISION, firmwareRevision);
123123
logger.debug("Identified device {} as a {}, type {}, revision {}, serial number {}", address,
124-
ManufacturerID, hardwareType, firmwareRevision, serialNo);
124+
manufacturerID, hardwareType, firmwareRevision, serialNo);
125125
} else {
126126
logger.debug("The KNX device with address {} does not expose a Device Object", address);
127127
}

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialClient.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Enumeration;
1616
import java.util.concurrent.ScheduledExecutorService;
1717

18-
import org.eclipse.jdt.annotation.NonNull;
18+
import org.eclipse.jdt.annotation.NonNullByDefault;
1919
import org.openhab.core.thing.ThingUID;
2020
import org.slf4j.Logger;
2121
import org.slf4j.LoggerFactory;
@@ -33,6 +33,7 @@
3333
* @author Simon Kaufmann - initial contribution and API.
3434
*
3535
*/
36+
@NonNullByDefault
3637
public class SerialClient extends AbstractKNXClient {
3738

3839
private final Logger logger = LoggerFactory.getLogger(SerialClient.class);
@@ -48,7 +49,7 @@ public SerialClient(int autoReconnectPeriod, ThingUID thingUID, int responseTime
4849
}
4950

5051
@Override
51-
protected @NonNull KNXNetworkLink establishConnection() throws KNXException, InterruptedException {
52+
protected KNXNetworkLink establishConnection() throws KNXException, InterruptedException {
5253
try {
5354
RXTXVersion.getVersion();
5455
logger.debug("Establishing connection to KNX bus through FT1.2 on serial port {}.", serialPort);
@@ -59,12 +60,13 @@ public SerialClient(int autoReconnectPeriod, ThingUID thingUID, int responseTime
5960
"The serial FT1.2 KNX connection requires the RXTX libraries to be available, but they could not be found!",
6061
e);
6162
} catch (KNXException e) {
62-
if (e.getMessage().startsWith("can not open serial port")) {
63+
final String msg = e.getMessage();
64+
if ((msg != null) && (msg.startsWith("can not open serial port"))) {
6365
StringBuilder sb = new StringBuilder("Available ports are:\n");
6466
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
6567
while (portList.hasMoreElements()) {
6668
CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
67-
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
69+
if ((id != null) && (id.getPortType() == CommPortIdentifier.PORT_SERIAL)) {
6870
sb.append(id.getName());
6971
sb.append("\n");
7072
}

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/config/BridgeConfiguration.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@
1414

1515
import java.math.BigDecimal;
1616

17-
import org.openhab.binding.knx.internal.handler.KNXBridgeBaseThingHandler;
17+
import org.eclipse.jdt.annotation.NonNullByDefault;
1818

1919
/**
20-
* {@link KNXBridgeBaseThingHandler} configuration
20+
* {@link org.openhab.binding.knx.internal.handler.KNXBridgeBaseThingHandler} configuration
2121
*
2222
* @author Simon Kaufmann - initial contribution and API
2323
*
2424
*/
25+
@NonNullByDefault
2526
public class BridgeConfiguration {
26-
private int autoReconnectPeriod;
27-
private BigDecimal readingPause;
28-
private BigDecimal readRetriesLimit;
29-
private BigDecimal responseTimeout;
27+
private int autoReconnectPeriod = 0;
28+
private BigDecimal readingPause = BigDecimal.valueOf(0);
29+
private BigDecimal readRetriesLimit = BigDecimal.valueOf(0);
30+
private BigDecimal responseTimeout = BigDecimal.valueOf(0);
3031

3132
public int getAutoReconnectPeriod() {
3233
return autoReconnectPeriod;

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/config/DeviceConfig.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414

1515
import java.math.BigDecimal;
1616

17+
import org.eclipse.jdt.annotation.NonNullByDefault;
18+
1719
/**
1820
* Configuration object for the device thing handler.
1921
*
2022
* @author Karel Goderis - Initial contribution
2123
* @author Simon Kaufmann - refactoring & cleanup
2224
*/
25+
@NonNullByDefault
2326
public class DeviceConfig {
2427

25-
private String address;
26-
private boolean fetch;
27-
private BigDecimal pingInterval;
28-
private BigDecimal readInterval;
28+
private String address = "";
29+
private boolean fetch = false;
30+
private BigDecimal pingInterval = BigDecimal.valueOf(0);
31+
private BigDecimal readInterval = BigDecimal.valueOf(0);
2932

3033
public String getAddress() {
3134
return address;

0 commit comments

Comments
 (0)