Skip to content

Commit 4f49bc2

Browse files
committed
fix for #22461 jar with empty ClassPath attribute
1 parent ef7f217 commit 4f49bc2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ClassPathFactory {
4343
yield newClassPath(entry)
4444

4545
def classesInExpandedPath(path: String)(using Context): IndexedSeq[ClassPath] =
46-
classesInPathImpl(path, expand = true).toIndexedSeq
46+
if path.trim.isEmpty then IndexedSeq.empty[ClassPath] else classesInPathImpl(path, expand = true).toIndexedSeq
4747

4848
def classesInPath(path: String)(using Context): List[ClassPath] = classesInPathImpl(path, expand = false)
4949

@@ -69,8 +69,10 @@ class ClassPathFactory {
6969
a <- ClassPath.expandManifestPath(file.absolutePath)
7070
path = java.nio.file.Paths.get(a.toURI()).nn
7171
if Files.exists(path)
72+
entry = AbstractFile.getFile(path)
73+
if Option(entry).nonEmpty
7274
yield
73-
newClassPath(AbstractFile.getFile(path))
75+
newClassPath(entry)
7476
else
7577
Seq.empty
7678

@@ -79,9 +81,10 @@ class ClassPathFactory {
7981
end classesInPathImpl
8082

8183
private def createSourcePath(file: AbstractFile)(using Context): ClassPath =
82-
if (file.isJarOrZip)
84+
val nonNull = Option(file).nonEmpty
85+
if (nonNull && file.isJarOrZip)
8386
ZipAndJarSourcePathFactory.create(file)
84-
else if (file.isDirectory)
87+
else if (nonNull && file.isDirectory)
8588
new DirectorySourcePath(file.file)
8689
else
8790
sys.error(s"Unsupported sourcepath element: $file")

compiler/src/dotty/tools/dotc/classpath/FileUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object FileUtils {
3434
def isScalaOrJavaSource: Boolean = !file.isDirectory && file.ext.isScalaOrJava
3535

3636
// TODO do we need to check also other files using ZipMagicNumber like in scala.tools.nsc.io.Jar.isJarOrZip?
37-
def isJarOrZip: Boolean = file.ext.isJarOrZip
37+
def isJarOrZip: Boolean = Option(file).nonEmpty && file.ext.isJarOrZip
3838

3939
/**
4040
* Safe method returning a sequence containing one URL representing this file, when underlying file exists,

0 commit comments

Comments
 (0)