From 1a547fdd2a38582061904e9914190a7a5c6f1980 Mon Sep 17 00:00:00 2001 From: Joseph Ottinger Date: Tue, 2 Apr 2024 16:56:28 -0400 Subject: [PATCH] Cleaning up warnings from deprecated code --- .../operations/urlcontent/URLFromMessageParser.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/javabot/operations/urlcontent/URLFromMessageParser.kt b/src/main/kotlin/javabot/operations/urlcontent/URLFromMessageParser.kt index 5532101b..ed4e5b0e 100644 --- a/src/main/kotlin/javabot/operations/urlcontent/URLFromMessageParser.kt +++ b/src/main/kotlin/javabot/operations/urlcontent/URLFromMessageParser.kt @@ -1,5 +1,6 @@ package javabot.operations.urlcontent +import java.net.URI import java.net.URL import java.util.ArrayList import java.util.stream.Collectors @@ -20,7 +21,7 @@ class URLFromMessageParser { val url = if (idxSpace == -1) message.substring(idxHttp) else message.substring(idxHttp, idxSpace) - potentialUrlsFound.add(stripPunctuation(message, url, idxHttp)) + potentialUrlsFound.add(stripPunctuation(url)) idxHttp = if (idxSpace == -1) -1 else message.indexOf("http", idxSpace) } @@ -29,7 +30,7 @@ class URLFromMessageParser { return list } - private fun stripPunctuation(message: String, url: String, idxUrlStart: Int): String { + private fun stripPunctuation(url: String): String { val last = url[url.length - 1] val idxPunc = ArrayUtils.indexOf(CLOSE_PUNCTUATION, last) @@ -42,7 +43,7 @@ class URLFromMessageParser { private fun urlFromToken(token: String): URL? { return try { - val url = URL(token) + val url = URI(token).toURL() if (blacklistHosts.contains(url.host)) null else url } catch (e: Exception) { null @@ -57,8 +58,8 @@ class URLFromMessageParser { this::class .java .getResourceAsStream("/urlBlacklist.csv") - .bufferedReader(Charsets.UTF_8) - .use { it.lines().collect(Collectors.toList()) } + ?.bufferedReader(Charsets.UTF_8) + .use { it!!.lines().collect(Collectors.toList()) } } catch (ignored: Exception) { emptyList() }