diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java index 5247544d413..8ae892082cf 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java @@ -298,11 +298,9 @@ protected boolean remoteEnabled() { try { Configuration configuration = configurationAdmin.getConfiguration("org.openhab.addons", null); Dictionary properties = configuration.getProperties(); - if (properties == null) { - // if we can't determine a set property, we use true (default is remote enabled) - return true; - } - return ConfigParser.valueAsOrElse(properties.get(CONFIG_REMOTE_ENABLED), Boolean.class, true); + // if we can't determine a set property, we use true (default is remote enabled) + return (properties == null) + || ConfigParser.valueAsOrElse(properties.get(CONFIG_REMOTE_ENABLED), Boolean.class, true); } catch (IOException e) { return true; } @@ -312,11 +310,9 @@ protected boolean includeIncompatible() { try { Configuration configuration = configurationAdmin.getConfiguration("org.openhab.addons", null); Dictionary properties = configuration.getProperties(); - if (properties == null) { - // if we can't determine a set property, we use false (default is show compatible only) - return false; - } - return ConfigParser.valueAsOrElse(properties.get(CONFIG_INCLUDE_INCOMPATIBLE), Boolean.class, false); + // if we can't determine a set property, we use false (default is show compatible only) + return (properties != null) + && ConfigParser.valueAsOrElse(properties.get(CONFIG_INCLUDE_INCOMPATIBLE), Boolean.class, false); } catch (IOException e) { return false; } diff --git a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java index 1b68723a2d8..4f03b842ae6 100644 --- a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java +++ b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java @@ -221,11 +221,8 @@ protected synchronized void unsetStorageCipher(StorageCipher storageCipher) { } private boolean isExpired(@Nullable Instant lastUsed) { - if (lastUsed == null) { - return false; - } // (last used + 183 days < now) then it is expired - return lastUsed.plus(EXPIRE_DAYS, ChronoUnit.DAYS).isBefore(Instant.now()); + return (lastUsed != null) && lastUsed.plus(EXPIRE_DAYS, ChronoUnit.DAYS).isBefore(Instant.now()); } /** diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/CompareConditionHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/CompareConditionHandler.java index 5de6b1fd0a1..0fbd83a0f84 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/CompareConditionHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/CompareConditionHandler.java @@ -89,38 +89,22 @@ public boolean isSatisfied(Map context) { case "GT": case ">": // Greater - if (toCompare == null) { - return false; - } else { - return compare(toCompare, rightValue) > 0; - } + return (toCompare != null) && (compare(toCompare, rightValue) > 0); case "gte": case "GTE": case ">=": case "=>": // Greater or equal - if (toCompare == null) { - return false; - } else { - return compare(toCompare, rightValue) >= 0; - } + return (toCompare != null) && (compare(toCompare, rightValue) >= 0); case "lt": case "LT": case "<": - if (toCompare == null) { - return false; - } else { - return compare(toCompare, rightValue) < 0; - } + return (toCompare != null) && (compare(toCompare, rightValue) < 0); case "lte": case "LTE": case "<=": case "=<": - if (toCompare == null) { - return false; - } else { - return compare(toCompare, rightValue) <= 0; - } + return (toCompare != null) && (compare(toCompare, rightValue) <= 0); case "matches": // Matcher... if (toCompare instanceof String string1 && rightValue instanceof String string2) { diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/i18n/ConfigDescriptionI18nUtil.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/i18n/ConfigDescriptionI18nUtil.java index 9aaadfc1831..0a588f7dc8a 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/i18n/ConfigDescriptionI18nUtil.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/i18n/ConfigDescriptionI18nUtil.java @@ -106,9 +106,6 @@ private String inferKey(boolean checkAddonType, URI configDescriptionURI, String } private boolean isValidPropertyKey(@Nullable String key) { - if (key != null) { - return !DELIMITER.matcher(key).find(); - } - return false; + return (key != null) && !DELIMITER.matcher(key).find(); } } diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/validation/TypeIntrospections.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/validation/TypeIntrospections.java index 881009aac27..9ee9036d824 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/validation/TypeIntrospections.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/validation/TypeIntrospections.java @@ -193,10 +193,7 @@ private FloatIntrospection() { @Override boolean isAssignable(Object value) { - if (!super.isAssignable(value)) { - return isBigDecimalInstance(value); - } - return true; + return super.isAssignable(value) || isBigDecimalInstance(value); } } @@ -208,10 +205,7 @@ private IntegerIntrospection() { @Override boolean isAssignable(Object value) { - if (!super.isAssignable(value)) { - return isBigDecimalInstance(value); - } - return true; + return super.isAssignable(value) || isBigDecimalInstance(value); } } @@ -223,18 +217,12 @@ private StringIntrospection() { @Override boolean isMinViolated(Object value, BigDecimal min) { - if (min == null) { - return false; - } - return ((String) value).length() < min.intValueExact(); + return (min != null) && (((String) value).length() < min.intValueExact()); } @Override boolean isMaxViolated(Object value, BigDecimal max) { - if (max == null) { - return false; - } - return ((String) value).length() > max.intValueExact(); + return (max != null) && (((String) value).length() > max.intValueExact()); } } } diff --git a/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDevice.java b/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDevice.java index b4b1cddd39b..1b8c2c6e289 100644 --- a/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDevice.java +++ b/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDevice.java @@ -142,10 +142,7 @@ public SddpDevice(Map headers, boolean offline) { */ @Override public boolean equals(@Nullable Object obj) { - if (obj instanceof SddpDevice other) { - return Objects.equals(from, other.from); - } - return false; + return (obj instanceof SddpDevice other) && Objects.equals(from, other.from); } /** diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/PersistentInbox.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/PersistentInbox.java index 9a1f8637246..e0f522922d9 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/PersistentInbox.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/PersistentInbox.java @@ -123,10 +123,8 @@ public void run() { private boolean isResultExpired(DiscoveryResult result, Instant now) { long ttl = result.getTimeToLive(); - if (ttl == DiscoveryResult.TTL_UNLIMITED) { - return false; - } - return Instant.ofEpochMilli(result.getTimestamp()).plusSeconds(ttl).isBefore(now); + return (ttl != DiscoveryResult.TTL_UNLIMITED) + && Instant.ofEpochMilli(result.getTimestamp()).plusSeconds(ttl).isBefore(now); } } diff --git a/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/AddonConsoleCommandExtension.java b/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/AddonConsoleCommandExtension.java index 0527fc91573..e888dfa78bb 100644 --- a/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/AddonConsoleCommandExtension.java +++ b/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/AddonConsoleCommandExtension.java @@ -50,10 +50,8 @@ public class AddonConsoleCommandExtension extends AbstractConsoleCommandExtensio private class AddonConsoleCommandCompleter implements ConsoleCommandCompleter { @Override public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List candidates) { - if (cursorArgumentIndex <= 0) { - return SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates); - } - return false; + return (cursorArgumentIndex <= 0) + && SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates); } } 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 267416435c6..9eadf6ceb37 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 @@ -794,10 +794,7 @@ private boolean isLeaf(EList children) { private boolean blockUntilChangeOccurs(String sitemapname, @Nullable String pageId) { EList widgets = subscriptions.collectWidgets(sitemapname, pageId); - if (widgets.isEmpty()) { - return false; - } - return waitForChanges(widgets); + return (!widgets.isEmpty()) && waitForChanges(widgets); } /** diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareImpl.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareImpl.java index 932aa0b160c..aa0d4756d3b 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareImpl.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareImpl.java @@ -212,10 +212,7 @@ public Map getProperties() { @Override public boolean isSuccessorVersion(@Nullable String firmwareVersion) { - if (firmwareVersion == null) { - return false; - } - return version.compare(new Version(firmwareVersion)) > 0; + return (firmwareVersion != null) && (version.compare(new Version(firmwareVersion)) > 0); } @Override diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/TimestampOffsetProfile.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/TimestampOffsetProfile.java index a69d677eb54..db521ff174c 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/TimestampOffsetProfile.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/TimestampOffsetProfile.java @@ -16,7 +16,6 @@ import java.time.Instant; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.thing.profiles.ProfileCallback; import org.openhab.core.thing.profiles.ProfileContext; @@ -63,10 +62,6 @@ public TimestampOffsetProfile(ProfileCallback callback, ProfileContext context) } } - private @Nullable String toStringOrNull(@Nullable Object value) { - return value == null ? null : value.toString(); - } - @Override public ProfileTypeUID getProfileTypeUID() { return SystemProfiles.TIMESTAMP_OFFSET; diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/AbstractLink.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/AbstractLink.java index 0e9affeae13..f3930536da7 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/AbstractLink.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/AbstractLink.java @@ -56,10 +56,7 @@ protected AbstractLink() { @Override public boolean equals(@Nullable Object obj) { - if (obj instanceof AbstractLink link) { - return getUID().equals(link.getUID()); - } - return false; + return (obj instanceof AbstractLink link) && getUID().equals(link.getUID()); } /** diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java index b77d58c700b..8d1fa36b4a7 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java @@ -126,10 +126,7 @@ protected List getExtensibleChannelTypeIds(Map attribute protected boolean getListed(Map attributes) { String listedFlag = attributes.get("listed"); - if (listedFlag != null) { - return Boolean.parseBoolean(listedFlag); - } - return true; + return (listedFlag == null) || Boolean.parseBoolean(listedFlag); } protected @Nullable String getRepresentationProperty(NodeIterator nodeIterator) { diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java index 7db8de5c768..d3ad2e3a2c8 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java @@ -748,10 +748,7 @@ public List getDialogRegistrations() { } private boolean checkLocales(Set supportedLocales, Locale locale) { - if (supportedLocales.isEmpty()) { - return true; - } - return supportedLocales.stream().anyMatch(sLocale -> { + return supportedLocales.isEmpty() || supportedLocales.stream().anyMatch(sLocale -> { var country = sLocale.getCountry(); return Objects.equals(sLocale.getLanguage(), locale.getLanguage()) && (country == null || country.isBlank() || country.equals(locale.getCountry())); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/i18n/LocalizedKey.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/i18n/LocalizedKey.java index a669e233472..5498c6a314c 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/i18n/LocalizedKey.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/i18n/LocalizedKey.java @@ -62,9 +62,6 @@ public boolean equals(@Nullable Object obj) { return false; } LocalizedKey other = (LocalizedKey) obj; - if (!Objects.equals(key, other.key)) { - return false; - } - return Objects.equals(locale, other.locale); + return Objects.equals(key, other.key) && Objects.equals(locale, other.locale); } } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/events/ThreadedEventHandler.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/events/ThreadedEventHandler.java index 480b411a364..32e050ddd46 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/events/ThreadedEventHandler.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/events/ThreadedEventHandler.java @@ -60,7 +60,7 @@ public class ThreadedEventHandler implements Closeable { logger.trace("inspect event: {}", event); if (event == null) { logger.debug("Hey, you have really very few events."); - } else if (event.equals(notifyEvent)) { + } else if (event.equals(notifyEvent)) { // NOPMD // received an internal notification } else { worker.handleEvent(event); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/LanguageResourceBundleManager.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/LanguageResourceBundleManager.java index 34a5f004e1c..44701445ca9 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/LanguageResourceBundleManager.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/LanguageResourceBundleManager.java @@ -81,11 +81,7 @@ public void clearCache() { * @return true if the specified resource is managed by this instance, otherwise false */ public boolean containsResource(String resource) { - if (resource != null) { - return this.resourceNames.contains(resource); - } - - return false; + return (resource != null) && this.resourceNames.contains(resource); } /** diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/CurrencyUnit.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/CurrencyUnit.java index 907011e9d01..f6a2014b676 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/CurrencyUnit.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/CurrencyUnit.java @@ -196,10 +196,7 @@ public boolean isEquivalentTo(@NonNullByDefault({}) Unit that) { @Override public boolean equals(@Nullable Object obj) { - if (obj instanceof CurrencyUnit that) { - return (name.equals(that.name) && Objects.equals(symbol, that.symbol)); - } - return false; + return (obj instanceof CurrencyUnit that) && (name.equals(that.name) && Objects.equals(symbol, that.symbol)); } @Override diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/common/SafeCallerImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/common/SafeCallerImplTest.java index 4a5386ebdc4..662a3315c59 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/common/SafeCallerImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/common/SafeCallerImplTest.java @@ -591,7 +591,7 @@ public AssertingThread(Runnable runnable) { @Override public void run() { try { - super.run(); + super.run(); // NOPMD } catch (AssertionError e) { AssertingThread.this.assertionError = e; } catch (RuntimeException e) { diff --git a/tools/static-code-analysis/pmd/suppressions.properties b/tools/static-code-analysis/pmd/suppressions.properties index cba6665f994..f7ca0bfbb9a 100644 --- a/tools/static-code-analysis/pmd/suppressions.properties +++ b/tools/static-code-analysis/pmd/suppressions.properties @@ -1,13 +1,9 @@ org.openhab.core.common.registry.AbstractRegistry=AvoidCatchingThrowable org.openhab.core.internal.common.SafeCallManagerImpl=CompareObjectsWithEquals -org.openhab.core.internal.events.ThreadedEventHandler=CompareObjectsWithEquals -org.openhab.core.internal.events.ThreadedEventHandler=EmptyIfStmt -org.openhab.core.thing.internal.ChannelItemProvider=CompareObjectsWithEquals -org.openhab.core.thing.internal.ThingManager=CompareObjectsWithEquals org.openhab.core.io.console.karaf.internal.OSGiConsole=SystemPrintln org.openhab.core.io.console.rfc147.internal.CommandWrapper=SystemPrintln org.openhab.core.io.console.rfc147.internal.OSGiConsole=SystemPrintln -org.openhab.core.io.net.http.internal.SecureHttpClientFactory=AvoidThrowingRawExceptionTypes +org.openhab.core.io.transport.modbus.internal.ModbusManagerImpl=MoreThanOneLogger org.openhab.core.model.core.internal.ModelRepositoryImpl=AvoidCatchingNPE org.openhab.core.model.script.interpreter.ScriptInterpreter=AvoidCatchingThrowable org.openhab.core.ui.internal.proxy.ProxyServletService=AvoidCatchingThrowable @@ -16,3 +12,4 @@ org.openhab.core.automation.internal.RuleRegistryImpl=CompareObjectsWithEquals org.openhab.core.automation.internal.provider.AutomationResourceBundlesEventQueue=AvoidCatchingThrowable org.openhab.core.io.console.karaf.internal.InstallServiceCommand=SystemPrintln org.openhab.core.common.PoolBasedSequentialScheduledExecutorService=CompareObjectsWithEquals +org.openhab.core.tools.UpgradeTool=SystemPrintln