Skip to content

Commit cbfa519

Browse files
committed
chore: Fix deprecated URL constructor for Java 21 compatibility
- Replace deprecated new URL() constructor with getClass.getResource() - Remove unused @nowarn annotation and classpathHandler
1 parent f65bc23 commit cbfa519

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

app/agent/origin.scala

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package agent
22

33
import java.io.FileNotFoundException
4-
import java.net.{URI, URL, URLConnection, URLStreamHandler}
5-
import scala.annotation.nowarn
4+
import java.net.URI
65

76
import collectors.Instance
87
import conf.{AWS, PrismConfiguration}
@@ -207,17 +206,6 @@ case class JsonOrigin(
207206
crawlRate: Map[String, CrawlRate]
208207
) extends Origin
209208
with Logging {
210-
private val classpathHandler = new URLStreamHandler {
211-
override def openConnection(u: URL): URLConnection = {
212-
Option(getClass.getResource(u.getPath))
213-
.map(_.openConnection())
214-
.getOrElse {
215-
throw new FileNotFoundException(
216-
"%s not found on classpath" format u.getPath
217-
)
218-
}
219-
}
220-
}
221209

222210
def credsFromS3Url(url: URI): AwsCredentialsProvider = {
223211
Option(url.getUserInfo) match {
@@ -234,15 +222,15 @@ case class JsonOrigin(
234222
}
235223

236224
def data(resource: ResourceType): JsValue = {
237-
@nowarn("cat=deprecation")
238225
val source: Source = new URI(
239226
url.replace("%resource%", resource.name)
240227
) match {
241228
case classPathLocation if classPathLocation.getScheme == "classpath" =>
242-
Source.fromURL(
243-
new URL(null, classPathLocation.toString, classpathHandler),
244-
"utf-8"
245-
)
229+
val path = classPathLocation.getPath
230+
val resourceURL = Option(getClass.getResource(path)).getOrElse {
231+
throw new FileNotFoundException(s"$path not found on classpath")
232+
}
233+
Source.fromURL(resourceURL, "utf-8")
246234
case s3Location if s3Location.getScheme == "s3" =>
247235
val s3Client = S3Client.builder
248236
.credentialsProvider(credsFromS3Url(s3Location))

0 commit comments

Comments
 (0)