diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/ToneSynthesizer.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/ToneSynthesizer.java index c6c7f613289..bb966d37e40 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/ToneSynthesizer.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/utils/ToneSynthesizer.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -112,17 +113,11 @@ public static Tone silenceTone(long millis) { } public ToneSynthesizer(AudioFormat audioFormat) { - assert audioFormat.getFrequency() != null; - this.sampleRate = audioFormat.getFrequency(); - assert audioFormat.getBitDepth() != null; - this.bitDepth = audioFormat.getBitDepth(); - assert audioFormat.getBitRate() != null; - this.bitRate = audioFormat.getBitRate(); - assert audioFormat.getChannels() != null; - this.channels = audioFormat.getChannels(); - var bigEndian = audioFormat.isBigEndian(); - assert bigEndian != null; - this.bigEndian = bigEndian; + this.sampleRate = Objects.requireNonNull(audioFormat.getFrequency()); + this.bitDepth = Objects.requireNonNull(audioFormat.getBitDepth()); + this.bitRate = Objects.requireNonNull(audioFormat.getBitRate()); + this.channels = Objects.requireNonNull(audioFormat.getChannels()); + this.bigEndian = Objects.requireNonNull(audioFormat.isBigEndian()); } /** diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/ModbusBitUtilities.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/ModbusBitUtilities.java index 8bc7bec1306..b80f6ec56a0 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/ModbusBitUtilities.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/ModbusBitUtilities.java @@ -278,9 +278,7 @@ public static short extractUInt8(byte[] bytes, int registerIndex, boolean hiByte public static short extractUInt8(byte[] bytes, int index) { assertIndexAndType(bytes, index, ValueType.UINT8); int signed = extractSInt8(bytes, index); - short unsigned = (short) (signed & 0xff); - assert unsigned >= 0; - return unsigned; + return (short) (signed & 0xff); } /** @@ -313,9 +311,7 @@ public static short extractSInt16(byte[] bytes, int index) { public static int extractUInt16(byte[] bytes, int index) { assertIndexAndType(bytes, index, ValueType.UINT16); int signed = extractSInt16(bytes, index); - int unsigned = signed & 0xffff; - assert unsigned >= 0; - return unsigned; + return signed & 0xffff; } /** @@ -350,9 +346,7 @@ public static int extractSInt32(byte[] bytes, int index) { public static long extractUInt32(byte[] bytes, int index) { assertIndexAndType(bytes, index, ValueType.UINT32); long signed = extractSInt32(bytes, index); - long unsigned = signed & 0xffff_ffffL; - assert unsigned >= 0; - return unsigned; + return signed & 0xffff_ffffL; } /** @@ -392,9 +386,7 @@ public static int extractSInt32Swap(byte[] bytes, int index) { public static long extractUInt32Swap(byte[] bytes, int index) { assertIndexAndType(bytes, index, ValueType.UINT32_SWAP); long signed = extractSInt32Swap(bytes, index); - long unsigned = signed & 0xffff_ffffL; - assert unsigned >= 0; - return unsigned; + return signed & 0xffff_ffffL; } /** diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/IntegrationTestSupport.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/IntegrationTestSupport.java index 0ec22cf398d..32bd4c06a26 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/IntegrationTestSupport.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/IntegrationTestSupport.java @@ -278,7 +278,7 @@ private void startSerialServer() { } public ModbusSlaveEndpoint getEndpoint() { - assert tcpModbusPort > 0; + assertTrue(tcpModbusPort > 0); return new ModbusTCPSlaveEndpoint("127.0.0.1", tcpModbusPort, false); } diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/SmokeTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/SmokeTest.java index fc37c3ca769..b8336badaa3 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/SmokeTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/SmokeTest.java @@ -157,7 +157,7 @@ public void testSlaveReadErrorResponse() throws Exception { try (ModbusCommunicationInterface comms = modbusManager.newModbusCommunicationInterface(endpoint, null)) { comms.submitOneTimePoll(new ModbusReadRequestBlueprint(SLAVE_UNIT_ID, ModbusReadFunctionCode.READ_MULTIPLE_REGISTERS, 0, 5, 1), result -> { - assert result.getRegisters().isPresent(); + assertTrue(result.getRegisters().isPresent()); okCount.incrementAndGet(); callbackCalled.countDown(); }, failure -> { @@ -194,7 +194,7 @@ public void testSlaveConnectionError() throws Exception { configuration)) { comms.submitOneTimePoll(new ModbusReadRequestBlueprint(SLAVE_UNIT_ID, ModbusReadFunctionCode.READ_MULTIPLE_REGISTERS, 0, 5, 1), result -> { - assert result.getRegisters().isPresent(); + assertTrue(result.getRegisters().isPresent()); okCount.incrementAndGet(); callbackCalled.countDown(); }, failure -> { @@ -228,7 +228,7 @@ public void testIOError() throws Exception { try (ModbusCommunicationInterface comms = modbusManager.newModbusCommunicationInterface(endpoint, null)) { comms.submitOneTimePoll(new ModbusReadRequestBlueprint(SLAVE_UNIT_ID, ModbusReadFunctionCode.READ_MULTIPLE_REGISTERS, 0, 5, 1), result -> { - assert result.getRegisters().isPresent(); + assertTrue(result.getRegisters().isPresent()); okCount.incrementAndGet(); callbackCalled.countDown(); }, failure -> { diff --git a/bundles/org.openhab.core.io.transport.mqtt/src/main/java/org/openhab/core/io/transport/mqtt/reconnect/PeriodicReconnectStrategy.java b/bundles/org.openhab.core.io.transport.mqtt/src/main/java/org/openhab/core/io/transport/mqtt/reconnect/PeriodicReconnectStrategy.java index 85c579efd54..75a062b2fd0 100644 --- a/bundles/org.openhab.core.io.transport.mqtt/src/main/java/org/openhab/core/io/transport/mqtt/reconnect/PeriodicReconnectStrategy.java +++ b/bundles/org.openhab.core.io.transport.mqtt/src/main/java/org/openhab/core/io/transport/mqtt/reconnect/PeriodicReconnectStrategy.java @@ -12,6 +12,7 @@ */ package org.openhab.core.io.transport.mqtt.reconnect; +import java.util.Objects; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -105,8 +106,7 @@ public synchronized void lostConnection() { return; } - assert scheduler != null; - scheduledTask = scheduler.scheduleWithFixedDelay(() -> { + scheduledTask = Objects.requireNonNull(scheduler).scheduleWithFixedDelay(() -> { MqttBrokerConnection brokerConnection = this.brokerConnection; // If the broker connections is not available anymore, stop the timed reconnect. if (brokerConnection == null) { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java index 524dc889a94..9207c5f7fd3 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java @@ -367,8 +367,7 @@ public > Unit getUnit(Class dimension) { throw new IllegalArgumentException("Dimension " + dimension.getName() + " is unknown. This is a bug."); } Unit unit = (Unit) map.get(getMeasurementSystem()); - assert unit != null; - return unit; + return Objects.requireNonNull(unit); } @Override diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/NumberItem.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/NumberItem.java index 3290503bec4..4570a39ea0f 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/NumberItem.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/NumberItem.java @@ -244,8 +244,7 @@ public void updatedMetadata(Metadata oldMetadata, Metadata newMetadata) { public void removedMetadata(Metadata metadata) { Class> dimension = this.dimension; if (dimension != null && UNIT_METADATA_NAMESPACE.equals(metadata.getUID().getNamespace())) { - assert unitProvider != null; - unit = unitProvider.getUnit((Class) dimension); + unit = Objects.requireNonNull(unitProvider).getUnit((Class) dimension); logger.trace("Item '{}' now has unit '{}'", name, unit); } } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/net/NetUtil.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/net/NetUtil.java index 020b7563c0b..92ef32cf939 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/net/NetUtil.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/net/NetUtil.java @@ -346,9 +346,8 @@ public static Collection getAllInterfaceAddresses() { } for (InterfaceAddress cidr : networkInterface.getInterfaceAddresses()) { - final InetAddress address = cidr.getAddress(); - assert address != null; // NetworkInterface.getInterfaceAddresses() should return only non-null - // addresses + // NetworkInterface.getInterfaceAddresses() should return only non-null addresses + final InetAddress address = Objects.requireNonNull(cidr.getAddress()); interfaceIPs.add(new CidrAddress(address, cidr.getNetworkPrefixLength())); } } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/TestUnitProvider.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/TestUnitProvider.java index 066e822f786..b6acdd2a301 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/TestUnitProvider.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/TestUnitProvider.java @@ -14,6 +14,7 @@ import java.util.Collection; import java.util.Map; +import java.util.Objects; import java.util.Set; import javax.measure.Quantity; @@ -38,9 +39,8 @@ public class TestUnitProvider implements UnitProvider { @Override @SuppressWarnings("unchecked") public > Unit getUnit(Class dimension) { - Unit unit = (Unit) dimensionMap.getOrDefault(dimension, Map.of()).get(SIUnits.getInstance()); - assert unit != null; - return unit; + return Objects + .requireNonNull((Unit) dimensionMap.getOrDefault(dimension, Map.of()).get(SIUnits.getInstance())); } @Override