-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix for #22461 Empty ClassPath attribute in one or more classpath jars causes crash #22462
base: main
Are you sure you want to change the base?
Conversation
I was interested in trying it out because this is more-or-less shared code with Scala 2. I did not yet reproduce. I would not expect to handle a possible null in more than one place. Dotty is usually complaining to me that such-and-such might be null, I have to sprinkle |
The critical change is here consisting of a The other changes don't address this bug, and are optional, intended to provide a more to-the-point error message. Wow, I just noticed I uninitentionally commited a file related to #22443. I will revert that and reduce other changes to the absolute minimum. |
4f49bc2
to
5e2bcf1
Compare
The proposed changes are now reduced to the bare minimum necessary. if Files.exists(path) // `path` is the empty String
entry = AbstractFile.getFile(path) // `entry` IS null (Windows only) I will try to manually verify this EDIT: the following script verifies the problem in Windows: #!/usr/bin/env -S scalaQ
object AbstractFileTest {
def main(args: Array[String]): Unit = {
import dotty.tools.io.AbstractFile
import java.nio.file.{Path, Paths, Files}
val path = Paths.get("")
printf("path [%s] exists : %s\n", path, Files.exists(path))
val entry = AbstractFile.getFile(path)
printf("entry [%s]\n", entry)
}
} # ./abstractFileTest.sc
[warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work.
[warning] Please be sure to update to the Scala CLI launcher to use the new features.
[warning] Check the Scala 3.5.0 release notes to troubleshoot your installation.
path [] exists : true
entry [null] EDIT: if Files.exists(path) with this: if path.toFile.exists EDIT: if path.trim.nonEmpty && Files.exists(path) |
The # WSL
$ wsl /opt/scala/bin/scala -e 'printf("%s\n", java.nio.file.Files.exists(java.nio.file.Paths.get("")))'
true # Windows
$ /opt/scala/bin/scala -e 'printf("%s\n", java.nio.file.Files.exists(java.nio.file.Paths.get("")))'
true |
To my surprise, the problem exists also in cd ~/workspace/scala3
sbt dist/Universal/packageBin
export SCALA_HOME=`pwd -P`/dist/linux-x86_64/target/universal/stage
export PATH="$SCALA_HOME/bin:$PATH" BTW, the universal distribution includes #!/usr/bin/env -S scala_legacy
object AbstractFileTest {
def main(args: Array[String]): Unit = {
import dotty.tools.io.AbstractFile
import java.nio.file.{Path, Paths, Files}
val path = Paths.get("")
printf("path [%s] exists : %s\n", path, Files.exists(path))
val entry = AbstractFile.getFile(path)
printf("entry [%s]\n", entry)
}
} and here's the output: (base) philwalk@d5:~/workspace/scala3$ ./abstractFileTest.sc
[warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work.
[warning] Please be sure to update to the Scala CLI launcher to use the new features.
[warning] Check the Scala 3.5.0 release notes to troubleshoot your installation.
path [] exists : true
entry [null] |
FYI the equivalent code on Scala 2 was changed to test I see there was one ancient attempt to improve the code in dotty, but I understand the assumption was that it would be replaced altogether at some point. I assume no one would object to any change you deem useful. I don't know whether this is useful information.
|
Change to how an empty or
null
jar manifestClassPath:
property is handled:in dotty.tools.dotc.classpath.ClassPathFactory:
classesInExpandedPath(...)
returns and emptyIndexedSeq
rather than crashisJarOrZip
returnsfalse
on anull
reference rather than crashin dotty.tools.dotc.classpath.FileUtils:
createSourcePath
fails with an error message on anull
file parameter.In the context of #22461, this causes an empty
ClassPath:
property to be treated the same as a mispelled or missing classpath entry, which are silently ignored, matching the behaviour of legacy scripts.