@@ -69,19 +69,30 @@ trait Macros extends MacroRuntimes with Traces with Helpers {
6969 ScalaClassLoader .fromURLs(classpath, self.getClass.getClassLoader)
7070 }
7171
72- import scala .tools .nsc .io .Jar
73- import scala .reflect .io .{AbstractFile , Path }
74- val locations = classpath.map(u => Path (AbstractFile .getURL(u).file))
7572 val disableCache = settings.YcacheMacroClassLoader .value == settings.CachePolicy .None .name
76- if (disableCache || locations.exists(! Jar .isJarOrZip(_))) {
77- if (disableCache) macroLogVerbose(" macro classloader: caching is disabled by the user." )
78- else {
79- val offenders = locations.filterNot(! Jar .isJarOrZip(_))
80- macroLogVerbose(s " macro classloader: caching is disabled because the following paths are not supported: ${offenders.mkString(" ," )}. " )
73+ if (disableCache) newLoader()
74+ else {
75+ import scala .tools .nsc .io .Jar
76+ import scala .reflect .io .{AbstractFile , Path }
77+
78+ val urlsAndFiles = classpath.map(u => u -> AbstractFile .getURL(u))
79+ val hasNullURL = urlsAndFiles.filter(_._2 eq null )
80+ if (hasNullURL.nonEmpty) {
81+ // TODO if the only null is jrt:// we can still cache
82+ // TODO filter out classpath elements pointing to non-existing files before we get here, that's another source of null
83+ macroLogVerbose(s " macro classloader: caching is disabled because `AbstractFile.getURL` returned `null` for ${hasNullURL.map(_._1).mkString(" , " )}. " )
84+ newLoader()
85+ } else {
86+ val locations = urlsAndFiles.map(t => Path (t._2.file))
87+ val nonJarZips = locations.filterNot(Jar .isJarOrZip(_))
88+ if (nonJarZips.nonEmpty) {
89+ macroLogVerbose(s " macro classloader: caching is disabled because the following paths are not supported: ${nonJarZips.mkString(" ," )}. " )
90+ newLoader()
91+ } else {
92+ macroClassLoadersCache.getOrCreate(locations.map(_.jfile.toPath()), newLoader)
93+ }
8194 }
82-
83- newLoader()
84- } else macroClassLoadersCache.getOrCreate(locations.map(_.jfile.toPath()), newLoader)
95+ }
8596 }
8697
8798 /** `MacroImplBinding` and its companion module are responsible for
0 commit comments