mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-314175 PathClassLoader disallows relative jar paths on the Java classpath
GitOrigin-RevId: 0de0f55b91c8b7bfee04113c62a5441a14bda9bf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1e50d7f319
commit
c4b1c60067
@@ -339,7 +339,10 @@ public final class ClassPath {
|
||||
return null;
|
||||
}
|
||||
|
||||
Path path = files[searchOffset++];
|
||||
// https://youtrack.jetbrains.com/issue/IDEA-314175
|
||||
// some environments (e.g. Bazel tests) put relative jar paths on the Java classpath,
|
||||
// because relative paths are useful for hermeticity.
|
||||
Path path = files[searchOffset++].toAbsolutePath();
|
||||
try {
|
||||
Loader loader = createLoader(path);
|
||||
if (loader != null) {
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.net.URL
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.invariantSeparatorsPathString
|
||||
|
||||
class PathClassLoaderTest {
|
||||
@Test
|
||||
@@ -24,4 +26,17 @@ class PathClassLoaderTest {
|
||||
assertThat(resource).isNotNull()
|
||||
assertThat(URL(resource!!.url, "screenshot.png").content).isEqualTo(expectedData)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `relative jar path`(@TempDir dir: Path) {
|
||||
// Regression test for IDEA-314175.
|
||||
val jarAbsolutePath = dir.resolve("lib.jar")
|
||||
Compressor.Zip(jarAbsolutePath.toFile()).use { compressor ->
|
||||
compressor.addFile("resource.txt", "contents".encodeToByteArray())
|
||||
}
|
||||
val jarRelativePath = Paths.get("").toAbsolutePath().relativize(jarAbsolutePath)
|
||||
val classPath = ClassPath(listOf(jarRelativePath), UrlClassLoader.build(), PathClassLoader.RESOURCE_FILE_FACTORY, true)
|
||||
val resource = checkNotNull(classPath.findResource("resource.txt"))
|
||||
assertThat(resource.url.toString()).isEqualTo("jar:file:${jarAbsolutePath.invariantSeparatorsPathString}!/resource.txt")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user