From d61a58ebee40c7d92edfac756815ba565ec39c33 Mon Sep 17 00:00:00 2001 From: Zabuzard Date: Wed, 24 Jun 2026 08:35:27 +0200 Subject: [PATCH] Fixed sonar issues --- .../features/help/HelpThreadCreatedListener.java | 2 +- .../projects/ProjectsThreadCreatedListener.java | 2 +- .../roleapplication/RoleApplicationHandler.java | 14 +++++--------- .../tjbot/features/rss/FailureState.java | 4 ++-- .../tjbot/features/rss/RSSHandlerRoutine.java | 8 +++++--- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java index c0f01b8245..1936a35d66 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java @@ -89,7 +89,7 @@ private boolean wasThreadAlreadyHandled(long threadChannelId) { Instant now = Instant.now(); // NOTE It is necessary to do the "check if exists, otherwise insert" atomic Instant createdAt = threadIdToCreatedAtCache.get(threadChannelId, _ -> now); - return createdAt != now; + return !createdAt.equals(now); } private void handleHelpThreadCreated(ThreadChannel threadChannel) { diff --git a/application/src/main/java/org/togetherjava/tjbot/features/projects/ProjectsThreadCreatedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/projects/ProjectsThreadCreatedListener.java index 18f51e9fe4..d46c384390 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/projects/ProjectsThreadCreatedListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/projects/ProjectsThreadCreatedListener.java @@ -51,7 +51,7 @@ public void onMessageReceived(MessageReceivedEvent event) { private boolean wasThreadAlreadyHandled(long threadChannelId) { Instant now = Instant.now(); Instant createdAt = threadIdToCreatedAtCache.get(threadChannelId, any -> now); - return createdAt != now; + return !createdAt.equals(now); } private boolean isPostMessage(ThreadChannel threadChannel, MessageReceivedEvent event) { diff --git a/application/src/main/java/org/togetherjava/tjbot/features/roleapplication/RoleApplicationHandler.java b/application/src/main/java/org/togetherjava/tjbot/features/roleapplication/RoleApplicationHandler.java index c5348bec5b..f9d3e73250 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/roleapplication/RoleApplicationHandler.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/roleapplication/RoleApplicationHandler.java @@ -18,8 +18,8 @@ import java.time.Duration; import java.time.Instant; -import java.time.OffsetDateTime; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; import java.util.regex.Pattern; @@ -35,7 +35,7 @@ public final class RoleApplicationHandler { private static final Logger logger = LoggerFactory.getLogger(RoleApplicationHandler.class); private static final int APPLICATION_SUBMIT_COOLDOWN_MINUTES = 5; - private final Cache applicationSubmitCooldown; + private final Cache applicationSubmitCooldown; private final Predicate applicationChannelPattern; private final RoleApplicationSystemConfig roleApplicationSystemConfig; @@ -125,10 +125,6 @@ private Optional getApplicationChannel(Guild guild) { .findFirst(); } - public Cache getApplicationSubmitCooldown() { - return applicationSubmitCooldown; - } - void submitApplicationFromModalInteraction(ModalInteractionEvent event, List args) { Guild guild = event.getGuild(); @@ -150,13 +146,13 @@ void submitApplicationFromModalInteraction(ModalInteractionEvent event, List fetchRSSItemsFromURL(String rssUrl) { "Possibly dead RSS feed URL: {} - Failed {} times. Please remove it from config.", rssUrl, newCount); } - circuitBreaker.put(rssUrl, new FailureState(newCount, ZonedDateTime.now())); + circuitBreaker.put(rssUrl, new FailureState(newCount, Instant.now())); long blacklistedHours = calculateWaitHours(newCount); @@ -476,8 +478,8 @@ private boolean isBackingOff(String url) { } long waitHours = calculateWaitHours(state.count()); - ZonedDateTime retryAt = state.lastFailure().plusHours(waitHours); + Instant retryAt = state.lastFailure().plus(waitHours, ChronoUnit.HOURS); - return ZonedDateTime.now().isBefore(retryAt); + return Instant.now().isBefore(retryAt); } }