From 07b95ca6684b4eafd1415586cabcedd0143da4c6 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Thu, 25 Mar 2021 20:18:08 +0100 Subject: [PATCH] Fix SAT findings (#2256) Fixes 65 SAT findings. Signed-off-by: Wouter Born --- .../internal/loader/DependencyTracker.java | 9 ++++-- .../internal/loader/ScriptFileReference.java | 28 +++++++++---------- .../internal/loader/ScriptFileWatcher.java | 15 ++++++---- .../internal/loader/ScriptLibraryWatcher.java | 6 ++-- .../loader/ScriptFileWatcherTest.java | 2 +- .../internal/ScriptEngineManagerImpl.java | 5 +--- .../internal/ScriptExtensionManager.java | 4 +-- .../rest/internal/RuleResource.java | 2 +- ...onfigDescriptionParameterGroupBuilder.java | 2 +- .../core/io/monitor/internal/EventLogger.java | 5 ++-- .../openhab/core/io/net/exec/ExecUtil.java | 1 - .../internal/WebClientFactoryImplTest.java | 2 +- .../core/internal/thing/ThingResource.java | 2 +- .../core/io/rest/ui/internal/UIResource.java | 2 +- .../resources/SystemInfoResource.java | 1 - .../io/transport/modbus/ModbusConstants.java | 5 +--- .../modbus/internal/ModbusManagerImpl.java | 1 - .../BitUtilitiesCommandToRegistersTest.java | 1 - .../test/BitUtilitiesExtractBitTest.java | 1 - .../modbus/test/IntegrationTestSupport.java | 12 ++++---- .../io/transport/modbus/test/SmokeTest.java | 24 ++++++++-------- .../test/WriteRequestJsonUtilitiesTest.java | 8 +++--- .../binding/internal/MagicServiceConfig.java | 18 ++++++------ .../main/resources/OH-INF/config/config.xml | 18 ++++++------ .../thing/internal/ThingFactoryHelper.java | 7 +++-- .../client/oauth2/AccessTokenResponse.java | 4 +-- .../core/internal/items/ExpireManager.java | 4 +-- .../core/library/types/QuantityType.java | 2 +- .../core/service/StartLevelService.java | 21 +++++++------- .../internal/scheduler/SchedulerImplTest.java | 8 +++--- .../org/openhab/core/util/UIDUtilsTest.java | 6 ++-- 31 files changed, 109 insertions(+), 117 deletions(-) diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/DependencyTracker.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/DependencyTracker.java index 9759905e47..d93cf15de1 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/DependencyTracker.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/DependencyTracker.java @@ -17,14 +17,19 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.openhab.core.automation.module.script.rulesupport.internal.loader.collection.BidiSetBag; -import org.osgi.service.component.annotations.*; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Tracks dependencies between scripts and reloads dependees * - * @author Jonathan Gilbert + * @author Jonathan Gilbert - Initial contribution */ @Component(immediate = true, service = DependencyTracker.class) public class DependencyTracker { diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileReference.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileReference.java index 5d877fc670..237ba9e179 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileReference.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileReference.java @@ -16,8 +16,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; -import java.util.HashSet; import java.util.Optional; import java.util.Set; import java.util.regex.Matcher; @@ -36,18 +34,18 @@ import org.slf4j.LoggerFactory; @NonNullByDefault public class ScriptFileReference implements Comparable { - private static final Set EXCLUDED_FILE_EXTENSIONS = new HashSet<>( - Arrays.asList("txt", "old", "example", "backup", "md", "swp", "tmp", "bak")); + private static final Set EXCLUDED_FILE_EXTENSIONS = Set.of("txt", "old", "example", "backup", "md", "swp", + "tmp", "bak"); - private static final Pattern[] startLevelPatterns = new Pattern[] { Pattern.compile(".*/sl(\\d{2})/[^/]+"), // script - // in - // immediate - // slXX - // directory + private static final Pattern[] START_LEVEL_PATTERNS = new Pattern[] { Pattern.compile(".*/sl(\\d{2})/[^/]+"), // script + // in + // immediate + // slXX + // directory Pattern.compile(".*/[^/]+\\.sl(\\d{2})\\.[^/.]+") // script named .slXX. }; - private static final Logger logger = LoggerFactory.getLogger(ScriptFileReference.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ScriptFileReference.class); private final URL scriptFileURL; @@ -60,13 +58,13 @@ public class ScriptFileReference implements Comparable { } public int getStartLevel() { - for (Pattern p : startLevelPatterns) { + for (Pattern p : START_LEVEL_PATTERNS) { Matcher m = p.matcher(scriptFileURL.getPath()); if (m.find() && m.groupCount() > 0) { try { return Integer.parseInt(m.group(1)); } catch (NumberFormatException nfe) { - logger.warn("Extracted start level {} from {}, but it's not an integer. Ignoring.", m.group(1), + LOGGER.warn("Extracted start level {} from {}, but it's not an integer. Ignoring.", m.group(1), scriptFileURL.getPath()); } } @@ -99,11 +97,11 @@ public class ScriptFileReference implements Comparable { try { Path path1 = Paths.get(scriptFileURL.toURI()); String name1 = path1.getFileName().toString(); - logger.trace("o1 [{}], path1 [{}], name1 [{}]", scriptFileURL, path1, name1); + LOGGER.trace("o1 [{}], path1 [{}], name1 [{}]", scriptFileURL, path1, name1); Path path2 = Paths.get(other.scriptFileURL.toURI()); String name2 = path2.getFileName().toString(); - logger.trace("o2 [{}], path2 [{}], name2 [{}]", other.scriptFileURL, path2, name2); + LOGGER.trace("o2 [{}], path2 [{}], name2 [{}]", other.scriptFileURL, path2, name2); int nameCompare = name1.compareToIgnoreCase(name2); if (nameCompare != 0) { @@ -112,7 +110,7 @@ public class ScriptFileReference implements Comparable { return path1.getParent().toString().compareToIgnoreCase(path2.getParent().toString()); } } catch (URISyntaxException e) { - logger.error("URI syntax exception", e); + LOGGER.error("URI syntax exception", e); return 0; } } diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcher.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcher.java index bbafbd89da..28a2ca59d2 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcher.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcher.java @@ -24,7 +24,10 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.WatchEvent; import java.nio.file.WatchEvent.Kind; -import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -38,7 +41,11 @@ import org.openhab.core.OpenHAB; import org.openhab.core.automation.module.script.ScriptEngineContainer; import org.openhab.core.automation.module.script.ScriptEngineManager; import org.openhab.core.common.NamedThreadFactory; -import org.openhab.core.service.*; +import org.openhab.core.service.AbstractWatchService; +import org.openhab.core.service.ReadyMarker; +import org.openhab.core.service.ReadyMarkerFilter; +import org.openhab.core.service.ReadyService; +import org.openhab.core.service.StartLevelService; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @@ -104,7 +111,7 @@ public class ScriptFileWatcher extends AbstractWatchService /** * Override the executor service. Can be used for testing. - * + * * @param executerFactory supplier of ScheduledExecutorService */ void setExecuterFactory(Supplier executerFactory) { @@ -175,7 +182,6 @@ public class ScriptFileWatcher extends AbstractWatchService } private synchronized void importFileWhenReady(ScriptFileReference ref) { - if (loaded.contains(ref)) { this.removeFile(ref); // if already loaded, remove first } @@ -192,7 +198,6 @@ public class ScriptFileWatcher extends AbstractWatchService } private void importFile(ScriptFileReference ref) { - String fileName = ref.getScriptFileURL().getFile(); Optional scriptType = ref.getScriptType(); assert scriptType.isPresent(); diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptLibraryWatcher.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptLibraryWatcher.java index ee066069aa..2f8ba5f0ea 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptLibraryWatcher.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptLibraryWatcher.java @@ -12,9 +12,7 @@ */ package org.openhab.core.automation.module.script.rulesupport.internal.loader; -import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; -import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE; -import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; +import static java.nio.file.StandardWatchEventKinds.*; import java.io.File; import java.nio.file.Path; @@ -26,7 +24,7 @@ import org.openhab.core.service.AbstractWatchService; /** * Listens for changes to script libraries * - * @author Jonathan Gilbert + * @author Jonathan Gilbert - Initial contribution */ abstract class ScriptLibraryWatcher extends AbstractWatchService { diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/test/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcherTest.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/test/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcherTest.java index fc1b73a5fc..443710ff26 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/test/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcherTest.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/test/java/org/openhab/core/automation/module/script/rulesupport/internal/loader/ScriptFileWatcherTest.java @@ -14,6 +14,7 @@ package org.openhab.core.automation.module.script.rulesupport.internal.loader; import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE; import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.io.File; @@ -206,7 +207,6 @@ class ScriptFileWatcherTest { @Test public void testLoadOneDefaultFileDelayedSupport() { - // set an executor which captures the scheduled task ScheduledExecutorService scheduledExecutorService = spy( new DelegatingScheduledExecutorService(Executors.newSingleThreadScheduledExecutor())); diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java index 813f41a66c..83dad1115b 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java @@ -12,9 +12,7 @@ */ package org.openhab.core.automation.module.script.internal; -import static org.openhab.core.automation.module.script.ScriptEngineFactory.CONTEXT_KEY_DEPENDENCY_LISTENER; -import static org.openhab.core.automation.module.script.ScriptEngineFactory.CONTEXT_KEY_ENGINE_IDENTIFIER; -import static org.openhab.core.automation.module.script.ScriptEngineFactory.CONTEXT_KEY_EXTENSION_ACCESSOR; +import static org.openhab.core.automation.module.script.ScriptEngineFactory.*; import java.io.InputStreamReader; import java.util.HashMap; @@ -140,7 +138,6 @@ public class ScriptEngineManagerImpl implements ScriptEngineManager { addAttributeToScriptContext(engine, CONTEXT_KEY_ENGINE_IDENTIFIER, engineIdentifier); addAttributeToScriptContext(engine, CONTEXT_KEY_EXTENSION_ACCESSOR, scriptExtensionManager); - } else { logger.error("ScriptEngine for language '{}' could not be created for identifier: {}", scriptType, engineIdentifier); diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManager.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManager.java index 5484200ee8..cd75c244af 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManager.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptExtensionManager.java @@ -101,13 +101,11 @@ public class ScriptExtensionManager implements ScriptExtensionAccessor { public void importDefaultPresets(ScriptEngineFactory engineProvider, ScriptEngine scriptEngine, String scriptIdentifier) { - engineProvider.scopeValues(scriptEngine, findDefaultPresets(scriptIdentifier)); } public Map importPreset(String preset, ScriptEngineFactory engineProvider, ScriptEngine scriptEngine, String scriptIdentifier) { - Map rv = findPreset(preset, scriptIdentifier); engineProvider.scopeValues(scriptEngine, rv); @@ -115,6 +113,7 @@ public class ScriptExtensionManager implements ScriptExtensionAccessor { return rv; } + @Override public Map findDefaultPresets(String scriptIdentifier) { Map allValues = new HashMap<>(); @@ -125,6 +124,7 @@ public class ScriptExtensionManager implements ScriptExtensionAccessor { return allValues; } + @Override public Map findPreset(String preset, String scriptIdentifier) { Map allValues = new HashMap<>(); for (ScriptExtensionProvider provider : scriptExtensionProviders) { diff --git a/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java b/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java index bbb8e288f9..29a60c5dc3 100644 --- a/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java +++ b/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java @@ -157,7 +157,7 @@ public class RuleResource implements RESTResource { Stream rules = ruleRegistry.stream().filter(p) // filter according to Predicates .map(rule -> EnrichedRuleDTOMapper.map(rule, ruleManager, managedRuleProvider)); // map matching rules - if (summary != null && summary == true) { + if (summary != null && summary) { rules = dtoMapper.limitToFields(rules, "uid,templateUID,name,visibility,description,status,tags,editable"); } diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameterGroupBuilder.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameterGroupBuilder.java index 1f23565f4e..7bc9d265ed 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameterGroupBuilder.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigDescriptionParameterGroupBuilder.java @@ -58,7 +58,7 @@ public class ConfigDescriptionParameterGroupBuilder { /** * Sets the advanced flag for this group. * - * @param advanced - true if the group contains advanced properties + * @param advanced true if the group contains advanced properties * @return the updated builder instance */ public ConfigDescriptionParameterGroupBuilder withAdvanced(@Nullable Boolean advanced) { diff --git a/bundles/org.openhab.core.io.monitor/src/main/java/org/openhab/core/io/monitor/internal/EventLogger.java b/bundles/org.openhab.core.io.monitor/src/main/java/org/openhab/core/io/monitor/internal/EventLogger.java index c45ee954d5..fd9dc77491 100644 --- a/bundles/org.openhab.core.io.monitor/src/main/java/org/openhab/core/io/monitor/internal/EventLogger.java +++ b/bundles/org.openhab.core.io.monitor/src/main/java/org/openhab/core/io/monitor/internal/EventLogger.java @@ -16,7 +16,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.events.Event; @@ -92,12 +91,12 @@ public class EventLogger implements EventSubscriber, ReadyTracker { } @Override - public void onReadyMarkerAdded(@NonNull ReadyMarker readyMarker) { + public void onReadyMarkerAdded(ReadyMarker readyMarker) { loggingActive = true; } @Override - public void onReadyMarkerRemoved(@NonNull ReadyMarker readyMarker) { + public void onReadyMarkerRemoved(ReadyMarker readyMarker) { loggingActive = false; } } diff --git a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/exec/ExecUtil.java b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/exec/ExecUtil.java index 9fde274880..08d670eb65 100644 --- a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/exec/ExecUtil.java +++ b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/exec/ExecUtil.java @@ -75,7 +75,6 @@ public class ExecUtil { */ public static @Nullable String executeCommandLineAndWaitResponse(@Nullable Duration timeout, String... commandLine) { - Process processTemp = null; Future outputFuture = null; cleanup: try { diff --git a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/WebClientFactoryImplTest.java b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/WebClientFactoryImplTest.java index d9992281ff..7c3b7fdaaa 100644 --- a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/WebClientFactoryImplTest.java +++ b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/WebClientFactoryImplTest.java @@ -101,7 +101,7 @@ public class WebClientFactoryImplTest { @Disabled("connecting to the outside world makes this test flaky") @Test - public void testCommonClientUsesExtensibleTrustManagerFailure() throws Throwable { + public void testCommonClientUsesExtensibleTrustManagerFailure() throws Exception { doThrow(new CertificateException()).when(extensibleTrustManager).checkServerTrusted( ArgumentMatchers.any(X509Certificate[].class), anyString(), ArgumentMatchers.any(SSLEngine.class)); HttpClient httpClient = webClientFactory.getCommonHttpClient(); diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingResource.java index a84dab9eec..5306b4314a 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/thing/ThingResource.java @@ -303,7 +303,7 @@ public class ThingResource implements RESTResource { Stream thingStream = thingRegistry.stream().map(t -> convertToEnrichedThingDTO(t, locale)) .distinct(); - if (summary != null && summary == true) { + if (summary != null && summary) { thingStream = dtoMapper.limitToFields(thingStream, "UID,label,bridgeUID,thingTypeUID,statusInfo,firmwareStatus,location,editable"); } diff --git a/bundles/org.openhab.core.io.rest.ui/src/main/java/org/openhab/core/io/rest/ui/internal/UIResource.java b/bundles/org.openhab.core.io.rest.ui/src/main/java/org/openhab/core/io/rest/ui/internal/UIResource.java index 1bac03cf6b..d91019847e 100644 --- a/bundles/org.openhab.core.io.rest.ui/src/main/java/org/openhab/core/io/rest/ui/internal/UIResource.java +++ b/bundles/org.openhab.core.io.rest.ui/src/main/java/org/openhab/core/io/rest/ui/internal/UIResource.java @@ -110,7 +110,7 @@ public class UIResource implements RESTResource { @QueryParam("summary") @Parameter(description = "summary fields only") @Nullable Boolean summary) { UIComponentRegistry registry = componentRegistryFactory.getRegistry(namespace); Stream components = registry.getAll().stream(); - if (summary != null && summary == true) { + if (summary != null && summary) { components = components.map(c -> { RootUIComponent component = new RootUIComponent(c.getUID(), c.getType()); @Nullable diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/SystemInfoResource.java b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/SystemInfoResource.java index b7fefe5324..d7384011d7 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/SystemInfoResource.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/resources/SystemInfoResource.java @@ -71,7 +71,6 @@ public class SystemInfoResource implements RESTResource { @Operation(operationId = "getSystemInformation", summary = "Gets information about the system.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SystemInfoBean.class))) }) public Response getSystemInfo(@Context UriInfo uriInfo) { - final SystemInfoBean bean = new SystemInfoBean(); return Response.ok(bean).build(); } diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/ModbusConstants.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/ModbusConstants.java index db2427fd64..bc48bec6b0 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/ModbusConstants.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/ModbusConstants.java @@ -14,7 +14,6 @@ package org.openhab.core.io.transport.modbus; import java.util.stream.Stream; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -115,9 +114,7 @@ public class ModbusConstants { * @return ValueType matching the config value * @throws IllegalArgumentException with unknown value types */ - @SuppressWarnings("null") - public static @NonNull ValueType fromConfigValue(@Nullable String configValueType) - throws IllegalArgumentException { + public static ValueType fromConfigValue(@Nullable String configValueType) throws IllegalArgumentException { return Stream.of(ValueType.values()).filter(v -> v.getConfigValue().equals(configValueType)).findFirst() .orElseThrow(() -> new IllegalArgumentException("Invalid valueType " + configValueType)); } diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java index 7f9800491a..629f912b04 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusManagerImpl.java @@ -961,7 +961,6 @@ public class ModbusManagerImpl implements ModbusManager { synchronized (this) { KeyedObjectPool connectionPool = this.connectionPool; if (connectionPool != null) { - for (ModbusCommunicationInterface commInterface : this.communicationInterfaces) { try { commInterface.close(); diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesCommandToRegistersTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesCommandToRegistersTest.java index 16130132c7..63706cabd2 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesCommandToRegistersTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesCommandToRegistersTest.java @@ -168,7 +168,6 @@ public class BitUtilitiesCommandToRegistersTest { * @return */ public static Stream data() { - return concatTestArgs(// a("1.0", BIT, IllegalArgumentException.class), a("1.0", INT8, IllegalArgumentException.class), diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractBitTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractBitTest.java index 4ce506ef8f..a4d32d1d79 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractBitTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractBitTest.java @@ -60,7 +60,6 @@ public class BitUtilitiesExtractBitTest { @Test public void testExtractBitWithRegisterIndexAndBitIndexOOB() { - byte[] bytes = new byte[] { 0b00100001, // hi byte of 1st register 0b00100101, // lo byte of 1st register 0b00110001, // hi byte of 2nd register 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 8618202c38..df920cbd2f 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 @@ -85,14 +85,14 @@ public class IntegrationTestSupport extends JavaTest { // One can perhaps test SERIAL with https://github.com/freemed/tty0tty // and using those virtual ports? Not the same thing as real serial device of course - private static String SERIAL_SERVER_PORT = "/dev/pts/7"; - private static String SERIAL_CLIENT_PORT = "/dev/pts/8"; + private static final String SERIAL_SERVER_PORT = "/dev/pts/7"; + private static final String SERIAL_CLIENT_PORT = "/dev/pts/8"; - private static SerialParameters SERIAL_PARAMETERS_CLIENT = new SerialParameters(SERIAL_CLIENT_PORT, 115200, + private static final SerialParameters SERIAL_PARAMETERS_CLIENT = new SerialParameters(SERIAL_CLIENT_PORT, 115200, SerialPort.FLOWCONTROL_NONE, SerialPort.FLOWCONTROL_NONE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE, Modbus.SERIAL_ENCODING_ASCII, false, 1000); - private static SerialParameters SERIAL_PARAMETERS_SERVER = new SerialParameters(SERIAL_SERVER_PORT, + private static final SerialParameters SERIAL_PARAMETERS_SERVER = new SerialParameters(SERIAL_SERVER_PORT, SERIAL_PARAMETERS_CLIENT.getBaudRate(), SERIAL_PARAMETERS_CLIENT.getFlowControlIn(), SERIAL_PARAMETERS_CLIENT.getFlowControlOut(), SERIAL_PARAMETERS_CLIENT.getDatabits(), SERIAL_PARAMETERS_CLIENT.getStopbits(), SERIAL_PARAMETERS_CLIENT.getParity(), @@ -106,14 +106,14 @@ public class IntegrationTestSupport extends JavaTest { /** * Max time to wait for connections/requests from client */ - protected int MAX_WAIT_REQUESTS_MILLIS = 1000; + protected static final int MAX_WAIT_REQUESTS_MILLIS = 1000; /** * The server runs in single thread, only one connection is accepted at a time. * This makes the tests as strict as possible -- connection must be closed. */ private static final int SERVER_THREADS = 1; - protected static int SLAVE_UNIT_ID = 1; + protected static final int SLAVE_UNIT_ID = 1; private static AtomicCounter udpServerIndex = new AtomicCounter(0); 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 466df820e0..7958281c5e 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 @@ -73,10 +73,10 @@ public class SmokeTest extends IntegrationTestSupport { private static final int DISCRETE_EVERY_N_TRUE = 3; private static final int HOLDING_REGISTER_MULTIPLIER = 1; private static final int INPUT_REGISTER_MULTIPLIER = 10; - private static final SpyingSocketFactory socketSpy = new SpyingSocketFactory(); + private static final SpyingSocketFactory SOCKET_SPY = new SpyingSocketFactory(); static { try { - Socket.setSocketImplFactory(socketSpy); + Socket.setSocketImplFactory(SOCKET_SPY); } catch (IOException e) { fail("Could not install socket spy in SmokeTest"); } @@ -138,7 +138,7 @@ public class SmokeTest extends IntegrationTestSupport { @BeforeEach public void setUpSocketSpy() throws IOException { - socketSpy.sockets.clear(); + SOCKET_SPY.sockets.clear(); } /** @@ -844,7 +844,7 @@ public class SmokeTest extends IntegrationTestSupport { config.setReconnectAfterMillis(9_000_000); // 1. capture open connections at this point - long openSocketsBefore = getNumberOfOpenClients(socketSpy); + long openSocketsBefore = getNumberOfOpenClients(SOCKET_SPY); assertThat(openSocketsBefore, is(equalTo(0L))); // 2. make poll, binding opens the tcp connection @@ -861,7 +861,7 @@ public class SmokeTest extends IntegrationTestSupport { } waitForAssert(() -> { // 3. ensure one open connection - long openSocketsAfter = getNumberOfOpenClients(socketSpy); + long openSocketsAfter = getNumberOfOpenClients(SOCKET_SPY); assertThat(openSocketsAfter, is(equalTo(1L))); }); try (ModbusCommunicationInterface comms2 = modbusManager.newModbusCommunicationInterface(endpoint, @@ -876,21 +876,21 @@ public class SmokeTest extends IntegrationTestSupport { }); assertTrue(latch.await(60, TimeUnit.SECONDS)); } - assertThat(getNumberOfOpenClients(socketSpy), is(equalTo(1L))); + assertThat(getNumberOfOpenClients(SOCKET_SPY), is(equalTo(1L))); // wait for moment (to check that no connections are closed) Thread.sleep(1000); // no more than 1 connection, even though requests are going through - assertThat(getNumberOfOpenClients(socketSpy), is(equalTo(1L))); + assertThat(getNumberOfOpenClients(SOCKET_SPY), is(equalTo(1L))); } Thread.sleep(1000); // Still one connection open even after closing second connection - assertThat(getNumberOfOpenClients(socketSpy), is(equalTo(1L))); + assertThat(getNumberOfOpenClients(SOCKET_SPY), is(equalTo(1L))); } // 4. close (the last) comms // ensure that open connections are closed // (despite huge "reconnect after millis") waitForAssert(() -> { - long openSocketsAfterClose = getNumberOfOpenClients(socketSpy); + long openSocketsAfterClose = getNumberOfOpenClients(SOCKET_SPY); assertThat(openSocketsAfterClose, is(equalTo(0L))); }); } @@ -909,7 +909,7 @@ public class SmokeTest extends IntegrationTestSupport { config.setReconnectAfterMillis(2_000); // 1. capture open connections at this point - long openSocketsBefore = getNumberOfOpenClients(socketSpy); + long openSocketsBefore = getNumberOfOpenClients(SOCKET_SPY); assertThat(openSocketsBefore, is(equalTo(0L))); // 2. make poll, binding opens the tcp connection @@ -927,14 +927,14 @@ public class SmokeTest extends IntegrationTestSupport { // Right after the poll we should have one connection open waitForAssert(() -> { // 3. ensure one open connection - long openSocketsAfter = getNumberOfOpenClients(socketSpy); + long openSocketsAfter = getNumberOfOpenClients(SOCKET_SPY); assertThat(openSocketsAfter, is(equalTo(1L))); }); // 4. Connection should close itself by the commons pool eviction policy (checking for old idle connection // every now and then) waitForAssert(() -> { // 3. ensure one open connection - long openSocketsAfter = getNumberOfOpenClients(socketSpy); + long openSocketsAfter = getNumberOfOpenClients(SOCKET_SPY); assertThat(openSocketsAfter, is(equalTo(0L))); }, 60_000, 50); diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/WriteRequestJsonUtilitiesTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/WriteRequestJsonUtilitiesTest.java index c54c9d998e..8a485a2b2e 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/WriteRequestJsonUtilitiesTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/WriteRequestJsonUtilitiesTest.java @@ -35,14 +35,14 @@ import org.openhab.core.io.transport.modbus.json.WriteRequestJsonUtilities; */ public class WriteRequestJsonUtilitiesTest { - private static List MAX_REGISTERS = IntStream.range(0, MAX_REGISTERS_WRITE_COUNT).mapToObj(i -> "1") + private static final List MAX_REGISTERS = IntStream.range(0, MAX_REGISTERS_WRITE_COUNT).mapToObj(i -> "1") .collect(Collectors.toList()); - private static List OVER_MAX_REGISTERS = IntStream.range(0, MAX_REGISTERS_WRITE_COUNT + 1) + private static final List OVER_MAX_REGISTERS = IntStream.range(0, MAX_REGISTERS_WRITE_COUNT + 1) .mapToObj(i -> "1").collect(Collectors.toList()); - private static List MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT).mapToObj(i -> "1") + private static final List MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT).mapToObj(i -> "1") .collect(Collectors.toList()); - private static List OVER_MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT + 1).mapToObj(i -> "1") + private static final List OVER_MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT + 1).mapToObj(i -> "1") .collect(Collectors.toList()); @Test diff --git a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/internal/MagicServiceConfig.java b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/internal/MagicServiceConfig.java index 74e2e78ea4..784d37fd8d 100644 --- a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/internal/MagicServiceConfig.java +++ b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/internal/MagicServiceConfig.java @@ -29,20 +29,20 @@ public class MagicServiceConfig { public BigDecimal decimal; public Integer integer; - public String text_advanced; - public boolean boolean_advanced; - public BigDecimal decimal_advanced; - public Integer integer_advanced; + public String textAdvanced; + public boolean booleanAdvanced; + public BigDecimal decimalAdvanced; + public Integer integerAdvanced; public String requiredTextParameter; public String verifiedTextParameter; - public String select_limited; - public String select_variable; + public String selectLimited; + public String selectVariable; - public List multiselect_text_limit; - public List multiselect_integer_limit; + public List multiselectTextLimit; + public List multiselectIntegerLimit; - public BigDecimal select_decimal_limit; + public BigDecimal selectDecimalLimit; @Override public String toString() { diff --git a/bundles/org.openhab.core.test.magic/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.core.test.magic/src/main/resources/OH-INF/config/config.xml index 154df89ddd..928035c3c9 100644 --- a/bundles/org.openhab.core.test.magic/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.core.test.magic/src/main/resources/OH-INF/config/config.xml @@ -38,22 +38,22 @@ 42 - + A grouped text parameter. myText - + A grouped boolean parameter. false - + A grouped decimal parameter. 3.141592 - + A grouped integer parameter. 42 @@ -68,7 +68,7 @@ A text parameter which is required and must be verified by the user. true - + A select text parameter which is restricted to the given options. @@ -79,7 +79,7 @@ true value1 - + A select text parameter without limit. @@ -89,7 +89,7 @@ false - + An integer parameter limited to 3 @@ -107,7 +107,7 @@ - + An integer parameter limited to 3 @@ -125,7 +125,7 @@ - + A decimal parameter with options provided by the backend. true diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ThingFactoryHelper.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ThingFactoryHelper.java index fb3867f84c..bd00f3932e 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ThingFactoryHelper.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ThingFactoryHelper.java @@ -137,8 +137,9 @@ public class ThingFactoryHelper { final ChannelUID channelUID = new ChannelUID(thingUID, groupId, channelDefinition.getId()); final ChannelBuilder channelBuilder = createChannelBuilder(channelUID, channelDefinition, configDescriptionRegistry); - if (channelBuilder == null) + if (channelBuilder == null) { return null; + } return channelBuilder.withProperties(channelDefinition.getProperties()).build(); } @@ -169,7 +170,6 @@ public class ThingFactoryHelper { static ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelDefinition channelDefinition, ConfigDescriptionRegistry configDescriptionRegistry) { - ChannelType channelType = withChannelTypeRegistry(channelTypeRegistry -> { return (channelTypeRegistry != null) ? channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID()) @@ -182,8 +182,9 @@ public class ThingFactoryHelper { } String label = channelDefinition.getLabel(); - if (label == null) + if (label == null) { label = channelType.getLabel(); + } final ChannelBuilder channelBuilder = ChannelBuilder.create(channelUID, channelType.getItemType()) // .withType(channelType.getUID()) // diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java index 78be8482ad..216d73f2d1 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java @@ -16,8 +16,6 @@ import java.io.Serializable; import java.time.LocalDateTime; import java.util.Objects; -import org.eclipse.jdt.annotation.NonNull; - /** * This is the Access Token Response, a simple value-object that holds the result of the * from an Access Token Request, as listed in RFC 6749: @@ -112,7 +110,7 @@ public final class AccessTokenResponse implements Serializable, Cloneable { * by the authorization server. * @return true if object is not-initialized, or expired, or expired early due to buffer */ - public boolean isExpired(@NonNull LocalDateTime givenTime, int tokenExpiresInBuffer) { + public boolean isExpired(LocalDateTime givenTime, int tokenExpiresInBuffer) { return createdOn == null || createdOn.plusSeconds(expiresIn).minusSeconds(tokenExpiresInBuffer).isBefore(givenTime); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ExpireManager.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ExpireManager.java index ffadf51d98..8007b8d076 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ExpireManager.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ExpireManager.java @@ -293,7 +293,7 @@ public class ExpireManager implements EventSubscriber, RegistryChangeListener> extends Number UnitInitializer.init(); } - private transient final Logger logger = LoggerFactory.getLogger(QuantityType.class); + private final transient Logger logger = LoggerFactory.getLogger(QuantityType.class); private final Quantity quantity; diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/service/StartLevelService.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/service/StartLevelService.java index af63b5ebd4..633d554386 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/service/StartLevelService.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/service/StartLevelService.java @@ -26,7 +26,6 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.common.NamedThreadFactory; @@ -72,16 +71,16 @@ import org.slf4j.LoggerFactory; @Component(immediate = true, configurationPid = "org.openhab.startlevel", configurationPolicy = ConfigurationPolicy.REQUIRE) public class StartLevelService { - public final static String STARTLEVEL_MARKER_TYPE = "startlevel"; + public static final String STARTLEVEL_MARKER_TYPE = "startlevel"; - public final static int STARTLEVEL_OSGI = 10; - public final static int STARTLEVEL_MODEL = 20; - public final static int STARTLEVEL_STATES = 30; - public final static int STARTLEVEL_RULES = 40; - public final static int STARTLEVEL_RULEENGINE = 50; - public final static int STARTLEVEL_UI = 70; - public final static int STARTLEVEL_THINGS = 80; - public final static int STARTLEVEL_COMPLETE = 100; + public static final int STARTLEVEL_OSGI = 10; + public static final int STARTLEVEL_MODEL = 20; + public static final int STARTLEVEL_STATES = 30; + public static final int STARTLEVEL_RULES = 40; + public static final int STARTLEVEL_RULEENGINE = 50; + public static final int STARTLEVEL_UI = 70; + public static final int STARTLEVEL_THINGS = 80; + public static final int STARTLEVEL_COMPLETE = 100; private final Logger logger = LoggerFactory.getLogger(StartLevelService.class); @@ -91,7 +90,7 @@ public class StartLevelService { private final Set markers = ConcurrentHashMap.newKeySet(); private final Map trackers = new ConcurrentHashMap<>(); - private final Map slmarker = new ConcurrentHashMap<>(); + private final Map slmarker = new ConcurrentHashMap<>(); private @Nullable ScheduledFuture job; private final ScheduledExecutorService scheduler = Executors diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java index cd541f89a9..6cb8ca0488 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java @@ -81,7 +81,7 @@ public class SchedulerImplTest { @Test @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) - public void testAfterResolvedWithException() throws Throwable { + public void testAfterResolvedWithException() throws InterruptedException { Callable callable = () -> { // Pass a exception not very likely thrown by the scheduler it self to avoid missing real exceptions. throw new FileNotFoundException("testBeforeTimeoutException"); @@ -103,7 +103,7 @@ public class SchedulerImplTest { @Test @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) - public void testBeforeTimeoutException() throws Throwable { + public void testBeforeTimeoutException() throws InterruptedException, ExecutionException { CompletableFuture d = new CompletableFuture<>(); ScheduledCompletableFuture before = scheduler.before(d, Duration.ofMillis(100)); Thread.sleep(200); @@ -145,7 +145,7 @@ public class SchedulerImplTest { @Test @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) - public void testBeforeResolvedWithException() throws Throwable { + public void testBeforeResolvedWithException() throws InterruptedException { CompletableFuture d = new CompletableFuture<>(); ScheduledCompletableFuture before = scheduler.before(d, Duration.ofMillis(100)); // Pass an exception not very likely thrown by the scheduler it self to avoid missing real exceptions. @@ -164,7 +164,7 @@ public class SchedulerImplTest { @Test @Timeout(value = 300, unit = TimeUnit.MILLISECONDS) - public void testAfterTimeoutException() throws Throwable { + public void testAfterTimeoutException() throws InterruptedException, ExecutionException { CompletableFuture d = new CompletableFuture<>(); ScheduledCompletableFuture before = scheduler.before(d, Duration.ofMillis(100)); Thread.sleep(200); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/UIDUtilsTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/UIDUtilsTest.java index c18ea81df0..bb759d986f 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/util/UIDUtilsTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/util/UIDUtilsTest.java @@ -32,9 +32,9 @@ public class UIDUtilsTest { Consumer test = in -> { final String encoded = UIDUtils.encode(in); final String decoded = UIDUtils.decode(encoded); - System.out.printf("in: %s%n encoded: %s%n decoded: %s%n equals: %b%n", in, encoded, decoded, - in.equals(decoded)); - assertThat(decoded, IsEqual.equalTo(in)); + final String reason = String.format("in: %s%n encoded: %s%n decoded: %s%n equals: %b%n", in, encoded, + decoded, in.equals(decoded)); + assertThat(reason, decoded, IsEqual.equalTo(in)); }; test.accept("test"); test.accept("TEST");