Skip to content

Commit

Permalink
Cleaning up warnings from deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
jottinger committed Apr 2, 2024
1 parent bd03782 commit 1a547fd
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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()
}
Expand Down

0 comments on commit 1a547fd

Please sign in to comment.