From b90e87367daf303aad5f10b053413948916291f0 Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Sun, 16 Feb 2025 11:37:22 +0100 Subject: [PATCH] Fix JavaDoc, SAT and depreacation warnings (#4598) * Fix SAT and depreacation warnings * Fix JavaDoc build Signed-off-by: Holger Friedrich --- .../openhab/core/config/core/ConfigParser.java | 1 - .../ConfigValidationExceptionTest.java | 4 ++-- .../rest/sitemap/internal/SitemapResource.java | 3 ++- .../modbus/internal/ModbusPoolConfig.java | 6 ++++-- .../core/io/websocket/log/LogWebSocket.java | 6 +++--- .../extensions/PersistenceExtensions.java | 16 ++++++++-------- .../generic/converter/ColorChannelHandler.java | 3 ++- .../core/transform/actions/Transformation.java | 4 +--- .../common/AbstractInvocationHandler.java | 4 ++-- .../QuantityTypeArithmeticGroupFunction.java | 2 +- 10 files changed, 25 insertions(+), 24 deletions(-) diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigParser.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigParser.java index 6301769e7..ca64c5139 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigParser.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigParser.java @@ -79,7 +79,6 @@ public final class ConfigParser { @SuppressWarnings({ "rawtypes", "unchecked" }) public static @Nullable T configurationAs(Map properties, Class configurationClass) { - Constructor constructor; T configuration = null; try { diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java index 5f368190b..4ad430e54 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigValidationExceptionTest.java @@ -43,8 +43,8 @@ public class ConfigValidationExceptionTest { private static final String PARAM1 = "param1"; private static final String PARAM2 = "param2"; - private static final Locale DE = new Locale("de"); - private static final Locale EN = new Locale("en"); + private static final Locale DE = Locale.GERMAN; + private static final Locale EN = Locale.ENGLISH; private static final int MAX = 3; private static final String TXT_DE1 = "German 1"; diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java index 17839c57f..2cf2137f9 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java @@ -106,6 +106,7 @@ import org.openhab.core.model.sitemap.sitemap.Widget; import org.openhab.core.types.State; import org.openhab.core.ui.items.ItemUIRegistry; import org.openhab.core.ui.items.ItemUIRegistry.WidgetLabelSource; +import org.openhab.core.util.ColorUtil; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @@ -745,7 +746,7 @@ public class SitemapResource public static @Nullable String convertItemValueColor(@Nullable String color, @Nullable State itemState) { if ("itemValue".equals(color)) { if (itemState instanceof HSBType hsbState) { - return "#" + Integer.toHexString(hsbState.getRGB()).substring(2); + return "#" + Integer.toHexString(ColorUtil.hsbTosRgb(hsbState)).substring(2); } return null; } diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusPoolConfig.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusPoolConfig.java index 50bb88f3b..387c7245c 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusPoolConfig.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusPoolConfig.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.modbus.internal; +import java.time.Duration; + import org.apache.commons.pool2.impl.DefaultEvictionPolicy; import org.apache.commons.pool2.impl.EvictionPolicy; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; @@ -51,7 +53,7 @@ public class ModbusPoolConfig extends GenericKeyedObjectPoolConfig<@Nullable Mod setMaxTotalPerKey(1); // block infinitely when exhausted - setMaxWaitMillis(-1); + setMaxWait(Duration.ofMillis(-1)); // Connections are "tested" on return. Effectively, disconnected connections are destroyed when returning on // pool @@ -65,7 +67,7 @@ public class ModbusPoolConfig extends GenericKeyedObjectPoolConfig<@Nullable Mod // Evict idle connections every 10 seconds setEvictionPolicy(new ModbusSlaveConnectionEvictionPolicy()); - setTimeBetweenEvictionRunsMillis(10000); + setTimeBetweenEvictionRuns(Duration.ofMillis(10000)); // Let eviction re-create ready-to-use idle (=unconnected) connections // This is to avoid occasional / rare deadlocks seen with pool 2.8.1 & 2.4.3 when // borrow hangs (waiting indefinitely for idle object to appear in the pool) diff --git a/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/log/LogWebSocket.java b/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/log/LogWebSocket.java index 4210c56d2..6bd13f11c 100644 --- a/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/log/LogWebSocket.java +++ b/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/log/LogWebSocket.java @@ -67,8 +67,8 @@ public class LogWebSocket implements LogListener { private static final TypeToken> STRING_LIST_TYPE = (TypeToken>) TypeToken .getParameterized(List.class, String.class); - private final static int SEND_PERIOD = 100; // Minimum allowable time between log packets (in milliseconds) - private final static long FIRST_SEQUENCE = 0; + private static final int SEND_PERIOD = 100; // Minimum allowable time between log packets (in milliseconds) + private static final long FIRST_SEQUENCE = 0; private final Logger logger = LoggerFactory.getLogger(LogWebSocket.class); @@ -116,7 +116,7 @@ public class LogWebSocket implements LogListener { @OnWebSocketMessage public void onText(String message) { // Detect empty message (keepalive) and ignore - if (message.equals("{}")) { + if ("{}".equals(message)) { return; } diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java index d00b154ea..1fc56661a 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java @@ -332,7 +332,7 @@ public class PersistenceExtensions { /** * Query the last historic update time of a given item. The default persistence service is used. - * Note the {@link Item.getLastStateUpdate()} is generally preferred to get the last update time of an item. + * Note the {@link Item#getLastStateUpdate()} is generally preferred to get the last update time of an item. * * @param item the item for which the last historic update time is to be returned * @return point in time of the last historic update to item, null if there are no @@ -345,7 +345,7 @@ public class PersistenceExtensions { /** * Query for the last historic update time of a given item. - * Note the {@link Item.getLastStateUpdate()} is generally preferred to get the last update time of an item. + * Note the {@link Item#getLastStateUpdate()} is generally preferred to get the last update time of an item. * * @param item the item for which the last historic update time is to be returned * @param serviceId the name of the {@link PersistenceService} to use @@ -389,7 +389,7 @@ public class PersistenceExtensions { /** * Query the last historic change time of a given item. The default persistence service is used. - * Note the {@link Item.getLastStateChange()} is generally preferred to get the last state change time of an item. + * Note the {@link Item#getLastStateChange()} is generally preferred to get the last state change time of an item. * * @param item the item for which the last historic change time is to be returned * @return point in time of the last historic change to item, null if there are no @@ -402,7 +402,7 @@ public class PersistenceExtensions { /** * Query for the last historic change time of a given item. - * Note the {@link Item.getLastStateChange()} is generally preferred to get the last state change time of an item. + * Note the {@link Item#getLastStateChange()} is generally preferred to get the last state change time of an item. * * @param item the item for which the last historic change time is to be returned * @param serviceId the name of the {@link PersistenceService} to use @@ -512,7 +512,7 @@ public class PersistenceExtensions { /** * Returns the previous state of a given item. - * Note the {@link Item.getLastState()} is generally preferred to get the previous state of an item. + * Note the {@link Item#getLastState()} is generally preferred to get the previous state of an item. * * @param item the item to get the previous state value for * @return the previous state or null if no previous state could be found, or if the default @@ -524,7 +524,7 @@ public class PersistenceExtensions { /** * Returns the previous state of a given item. - * Note the {@link Item.getLastState()} is generally preferred to get the previous state of an item. + * Note the {@link Item#getLastState()} is generally preferred to get the previous state of an item. * * @param item the item to get the previous state value for * @param skipEqual if true, skips equal state values and searches the first state not equal the current state @@ -538,7 +538,7 @@ public class PersistenceExtensions { /** * Returns the previous state of a given item. * The {@link PersistenceService} identified by the serviceId is used. - * Note the {@link Item.getLastState()} is generally preferred to get the previous state of an item. + * Note the {@link Item#getLastState()} is generally preferred to get the previous state of an item. * * @param item the item to get the previous state value for * @param serviceId the name of the {@link PersistenceService} to use @@ -552,7 +552,7 @@ public class PersistenceExtensions { /** * Returns the previous state of a given item. * The {@link PersistenceService} identified by the serviceId is used. - * Note the {@link Item.getLastState()} is generally preferred to get the previous state of an item. + * Note the {@link Item#getLastState()} is generally preferred to get the previous state of an item. * * @param item the item to get the previous state value for * @param skipEqual if true, skips equal state values and searches the first state not equal the diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/generic/converter/ColorChannelHandler.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/generic/converter/ColorChannelHandler.java index b887106fe..ab5175c93 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/generic/converter/ColorChannelHandler.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/generic/converter/ColorChannelHandler.java @@ -28,6 +28,7 @@ import org.openhab.core.thing.internal.binding.generic.converter.AbstractTransfo import org.openhab.core.types.Command; import org.openhab.core.types.State; import org.openhab.core.types.UnDefType; +import org.openhab.core.util.ColorUtil; /** * The {@link ColorChannelHandler} implements {@link org.openhab.core.library.items.ColorItem} conversions @@ -122,7 +123,7 @@ public class ColorChannelHandler extends AbstractTransformingChannelHandler { private String hsbToString(HSBType state) { switch (channelConfig.colorMode) { case RGB: - PercentType[] rgb = state.toRGB(); + PercentType[] rgb = ColorUtil.hsbToRgbPercent(state); return String.format("%1$d,%2$d,%3$d", rgb[0].toBigDecimal().multiply(BYTE_FACTOR).intValue(), rgb[1].toBigDecimal().multiply(BYTE_FACTOR).intValue(), rgb[2].toBigDecimal().multiply(BYTE_FACTOR).intValue()); diff --git a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/actions/Transformation.java b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/actions/Transformation.java index 40c5ff3c8..312cc728b 100644 --- a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/actions/Transformation.java +++ b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/actions/Transformation.java @@ -17,7 +17,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.transform.TransformationException; import org.openhab.core.transform.TransformationHelper; import org.openhab.core.transform.TransformationService; -import org.openhab.core.transform.internal.TransformationActivator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,8 +31,7 @@ public class Transformation { private static @Nullable String trans(String type, String function, String value) throws TransformationException { String result; - TransformationService service = TransformationHelper - .getTransformationService(TransformationActivator.getContext(), type); + TransformationService service = TransformationHelper.getTransformationService(type); if (service != null) { result = service.transform(function, value); } else { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/common/AbstractInvocationHandler.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/common/AbstractInvocationHandler.java index ff99366d2..0b7b980e4 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/common/AbstractInvocationHandler.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/common/AbstractInvocationHandler.java @@ -108,14 +108,14 @@ abstract class AbstractInvocationHandler { void handleDuplicate(Method method, DuplicateExecutionException e) { Thread thread = Objects.requireNonNull(e.getCallable().getThread()); logger.debug(MSG_DUPLICATE, toString(method), target, toString(e.getCallable().getMethod()), thread.getName(), - thread.getId(), thread.getState().toString(), getStacktrace(thread)); + thread.threadId(), thread.getState().toString(), getStacktrace(thread)); } void handleTimeout(Method method, Invocation invocation) { final Thread thread = invocation.getThread(); if (thread != null) { logger.debug(MSG_TIMEOUT_R, timeout, toString(invocation.getInvocationStack()), thread.getName(), - thread.getId(), thread.getState().toString(), getStacktrace(thread)); + thread.threadId(), thread.getState().toString(), getStacktrace(thread)); } else { logger.debug(MSG_TIMEOUT_Q, timeout, toString(invocation.getInvocationStack())); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java index b4937c82f..cd8c0814a 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java @@ -146,7 +146,7 @@ public interface QuantityTypeArithmeticGroupFunction extends GroupFunction { /** * Calculates the sum of a set of item states whose value could be converted to the 'referenceUnit'. * - * Uses the {@link QuanitityType.add()} method so the result is an incremental sum based on the 'referenceUnit'. As + * Uses the {@link QuantityType#add} method so the result is an incremental sum based on the 'referenceUnit'. As * a general rule this class is instantiated with a 'referenceUnit' that is a "system unit" (which are zero based) * so such incremental sum is in fact also an absolute sum. However the class COULD be instantiated with a "non- * system unit" (e.g. °C, °F) in which case the result would be an incremental sum based on that unit.