Skip to content

Commit bf3326c

Browse files
committed
DirectoryClassPath: handle directory being removed under us
`dir.listFiles` will return null if called on a directory that no longer exists, somehow partest triggers that.
1 parent 2423ec9 commit bf3326c

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

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

+17-15
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,23 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
9999
case None => dir.listFiles()
100100
}
101101

102-
// Sort by file name for stable order of directory .class entries in package scope.
103-
// This gives stable results ordering of base type sequences for unrelated classes
104-
// with the same base type depth.
105-
//
106-
// Notably, this will stably infer`Product with Serializable`
107-
// as the type of `case class C(); case class D(); List(C(), D()).head`, rather than the opposite order.
108-
// On Mac, the HFS performs this sorting transparently, but on Linux the order is unspecified.
109-
//
110-
// Note this behaviour can be enabled in javac with `javac -XDsortfiles`, but that's only
111-
// intended to improve determinism of the compiler for compiler hackers.
112-
java.util.Arrays.sort(listing,
113-
new java.util.Comparator[File] {
114-
def compare(o1: File, o2: File) = o1.getName.compareTo(o2.getName)
115-
})
116-
listing
102+
if (listing != null) {
103+
// Sort by file name for stable order of directory .class entries in package scope.
104+
// This gives stable results ordering of base type sequences for unrelated classes
105+
// with the same base type depth.
106+
//
107+
// Notably, this will stably infer`Product with Serializable`
108+
// as the type of `case class C(); case class D(); List(C(), D()).head`, rather than the opposite order.
109+
// On Mac, the HFS performs this sorting transparently, but on Linux the order is unspecified.
110+
//
111+
// Note this behaviour can be enabled in javac with `javac -XDsortfiles`, but that's only
112+
// intended to improve determinism of the compiler for compiler hackers.
113+
java.util.Arrays.sort(listing,
114+
new java.util.Comparator[File] {
115+
def compare(o1: File, o2: File) = o1.getName.compareTo(o2.getName)
116+
})
117+
listing
118+
} else Array()
117119
}
118120
protected def getName(f: File): String = f.getName
119121
protected def toAbstractFile(f: File): AbstractFile = new PlainFile(new scala.reflect.io.File(f))

0 commit comments

Comments
 (0)