From 078121bedcef9cd717029826ab980d6d3c75185b Mon Sep 17 00:00:00 2001 From: java-coding-prodigy Date: Mon, 25 Sep 2023 19:45:03 +0530 Subject: [PATCH] make sonar happy --- .../wolframalpha/WolframAlphaHandler.java | 7 ++++--- .../mathcommands/wolframalpha/WolframAlphaImages.java | 11 ++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/mathcommands/wolframalpha/WolframAlphaHandler.java b/application/src/main/java/org/togetherjava/tjbot/features/mathcommands/wolframalpha/WolframAlphaHandler.java index ca17d32346..4b0719e98e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/mathcommands/wolframalpha/WolframAlphaHandler.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/mathcommands/wolframalpha/WolframAlphaHandler.java @@ -11,13 +11,14 @@ import org.togetherjava.tjbot.features.mathcommands.wolframalpha.api.*; import org.togetherjava.tjbot.features.mathcommands.wolframalpha.api.Error; -import java.awt.Color; +import java.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; -import java.io.UncheckedIOException; import java.net.HttpURLConnection; +import java.net.URISyntaxException; import java.net.http.HttpResponse; import java.util.*; +import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -169,7 +170,7 @@ private HandlerResponse handleSuccessfulResponse(QueryResult queryResult) { for (SubPod subPod : pod.getSubPods()) { try { images.add(WolframAlphaImages.renderSubPod(subPod)); - } catch (UncheckedIOException e) { + } catch (IOException | URISyntaxException e) { LOGGER.error( "Failed to render sub pod (title: '{}') from pod (title: '{}') from the WolframAlpha response (for query: '{}')", subPod.getTitle(), pod.getTitle(), query, e); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/mathcommands/wolframalpha/WolframAlphaImages.java b/application/src/main/java/org/togetherjava/tjbot/features/mathcommands/wolframalpha/WolframAlphaImages.java index 10a7e8a59c..3bad6ee03e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/mathcommands/wolframalpha/WolframAlphaImages.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/mathcommands/wolframalpha/WolframAlphaImages.java @@ -54,7 +54,7 @@ static BufferedImage renderTitle(String title) { return image; } - static BufferedImage renderSubPod(SubPod subPod) { + static BufferedImage renderSubPod(SubPod subPod) throws IOException, URISyntaxException { WolframAlphaImage sourceImage = subPod.getImage(); int widthPx = sourceImage.getWidth() + 2 * IMAGE_MARGIN_PX; @@ -64,12 +64,9 @@ static BufferedImage renderSubPod(SubPod subPod) { new BufferedImage(widthPx, heightPx, BufferedImage.TYPE_4BYTE_ABGR); Graphics graphics = destinationImage.getGraphics(); - try { - graphics.drawImage(ImageIO.read(new URI(sourceImage.getSource()).toURL()), - IMAGE_MARGIN_PX, IMAGE_MARGIN_PX, null); - } catch (IOException | URISyntaxException e) { - throw new RuntimeException(e); - } + graphics.drawImage(ImageIO.read(new URI(sourceImage.getSource()).toURL()), IMAGE_MARGIN_PX, + IMAGE_MARGIN_PX, null); + return destinationImage; }