-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix for #22461 Empty ClassPath attribute in one or more classpath jars causes crash #22462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
|
@philwalk Can you please drop the first commit and adjust the second ? The first commit has nothing to do this the original issue, and reverting it's change will only cause conflicts with your other PR when merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest making the change here instead:
for (m <- manifest ; cp <- m.attrs.get(Name.CLASS_PATH)) yield cp |
def classPathString: Option[String] =
for (m <- manifest ; cp <- m.attrs.get(Name.CLASS_PATH) if !cp.isBlank()) yield cp
Looking into it ... |
I commented on the ticket that the empty attribute is out of spec, so I like the clever idea of pushing the filter down to Jar. |
It's sounds like I can revert both commits and make your suggested change to |
Yes, just make sure to have a single commit please |
Also, just to be clear, this will revert the change to |
There is already a PR for that change: #22444 |
5e2bcf1
to
f24b5d1
Compare
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.Closes #22461