Skip to content

Commit 55f30ab

Browse files
IlyaMuravjovEgorkaKulikov
authored andcommitted
Avoid jdk.internal in org.usvm.instrumentation.util.URLClassPathLoader (#94)
1 parent 60a153a commit 55f30ab

File tree

1 file changed

+15
-19
lines changed
  • usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/util

1 file changed

+15
-19
lines changed
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
11
@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE")
22
package org.usvm.instrumentation.util
3-
import jdk.internal.loader.URLClassPath
4-
import jdk.internal.loader.Resource as InternalResource
53

64
import java.io.File
7-
import java.io.InputStream
85
import java.net.URL
9-
import java.security.AccessController
6+
import java.net.URLClassLoader
107
import java.security.CodeSigner
118

12-
class URLClassPathLoader(classPath: List<File>) {
9+
class URLClassPathLoader(private val classPath: List<File>) {
1310

1411
interface Resource {
1512
fun getName(): String
1613
fun getURL(): URL
1714
fun getCodeSourceURL(): URL
18-
fun getInputStream(): InputStream
19-
fun getContentLength(): Int
2015
fun getBytes(): ByteArray
2116
fun getCodeSigners(): Array<CodeSigner>?
2217
}
2318

24-
private class InternalResourceWrapper(val resource: InternalResource): Resource {
25-
override fun getName(): String = resource.name
26-
override fun getURL(): URL = resource.url
27-
override fun getCodeSourceURL(): URL = resource.codeSourceURL
28-
override fun getInputStream(): InputStream = resource.inputStream
29-
override fun getContentLength(): Int = resource.contentLength
30-
override fun getBytes(): ByteArray = resource.bytes
31-
override fun getCodeSigners(): Array<CodeSigner>? = resource.codeSigners
32-
}
33-
34-
private val urlClassPath = URLClassPath(classPath.map { it.toURI().toURL() }.toTypedArray(), AccessController.getContext())
19+
private val urlClassLoader = URLClassLoader(classPath.map { it.toURI().toURL() }.toTypedArray())
3520

36-
fun getResource(name: String): Resource = InternalResourceWrapper(urlClassPath.getResource(name, false))
21+
fun getResource(name: String): Resource {
22+
val resourceUrl = urlClassLoader.getResource(name) ?: error("Resource $name not found on classpath $classPath")
23+
return object : Resource {
24+
override fun getName(): String = name
25+
override fun getURL(): URL = resourceUrl
26+
// TODO usvm-sbft-merge: may be incorrect, especially for non-ASCII URLs
27+
override fun getCodeSourceURL(): URL = resourceUrl
28+
override fun getBytes(): ByteArray = resourceUrl.readBytes()
29+
// TODO usvm-sbft-merge: figure out the way to get code signers
30+
override fun getCodeSigners(): Array<CodeSigner>? = null
31+
}
32+
}
3733

3834
}

0 commit comments

Comments
 (0)