Skip to content

Compile to jar file in Windows crashes if the target jar is specified in classpath #10775

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

Open
philwalk opened this issue Dec 13, 2020 · 5 comments

Comments

@philwalk
Copy link
Contributor

Minimized code

$ scalac -classpath work.jar -d work.jar scala3test.sc

contents of file tmp/scala3test.sc:

object S3test {
  def main(args:Array[String]):Unit =
    println("Yo!")
}

There doesn't appear to be any problems in Linux, only Windows 10.

This complicates scripting support for very long classpaths, which effectively requires use of an @argsfile (wildcard classpath entries don't work in Windows currently). It leads to creation of two classpath args files, one for the compile phase and one for the runtime.

Output (click arrow to expand)

exception occurred while compiling scala3test.sc
java.nio.file.FileSystemException: C:\Users\philwalk\workspace\optue\work.jar: The process cannot access the file because it is being used by another process.
 while compiling scala3test.sc
Exception in thread "main" java.nio.file.FileSystemException: C:\Users\philwalk\workspace\optue\work.jar: The process cannot access the file because it is being used by another process.
        at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:274)
        at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:105)
        at java.base/java.nio.file.Files.delete(Files.java:1141)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.sync(ZipFileSystem.java:1357)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.lambda$close$2(ZipFileSystem.java:269)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.close(ZipFileSystem.java:268)
        at dotty.tools.io.JarArchive.close(JarArchive.scala:12)
        at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:71)
        at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:185)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$5(Run.scala:195)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:203)
        at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:210)
        at dotty.tools.dotc.Run.compileSources(Run.scala:147)
        at dotty.tools.dotc.Run.compile(Run.scala:129)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
        at dotty.tools.dotc.Driver.process(Driver.scala:193)
        at dotty.tools.dotc.Driver.process(Driver.scala:162)
        at dotty.tools.dotc.Driver.process(Driver.scala:174)
        at dotty.tools.dotc.Driver.main(Driver.scala:201)
        at dotty.tools.dotc.Main.main(Main.scala)
@smarter
Copy link
Member

smarter commented Dec 13, 2020

  • Can you confirm that this does not happen with Scala 2.13 ?
  • Can you check if using the -YdisableFlatCpCaching flag changes anything?

@michelou
Copy link
Contributor

In which environment do you run the scalac shell script on Windows ? bash shell in WSL or not ?

@som-snytt
Copy link
Contributor

som-snytt commented Dec 15, 2020

andre@DESKTOP-QD7ACD4 ~/snips
$ sdk use scala 2.13.4

Using scala version 2.13.4 in this shell.

andre@DESKTOP-QD7ACD4 ~/snips
$ scalac -d c.jar c.scala

andre@DESKTOP-QD7ACD4 ~/snips
$ scalac -d c.jar -classpath c.jar c.scala

andre@DESKTOP-QD7ACD4 ~/snips
$ sdk use scala 3.0.0-M1

Using scala version 3.0.0-M1 in this shell.

andre@DESKTOP-QD7ACD4 ~/snips
$ scalac -d c.jar c.scala

andre@DESKTOP-QD7ACD4 ~/snips
$ scalac -d c.jar -classpath c.jar c.scala
exception occurred while compiling c.scala
java.nio.file.FileSystemException: C:\cygwin64\home\andre\snips\c.jar: The process cannot access the fil
e because it is being used by another process.
 while compiling c.scala
Exception in thread "main" java.nio.file.FileSystemException: C:\cygwin64\home\andre\snips\c.jar: The pr
ocess cannot access the file because it is being used by another process.

        at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:274)

        at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:105)
        at java.base/java.nio.file.Files.delete(Files.java:1141)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.sync(ZipFileSystem.java:1328)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.lambda$close$2(ZipFileSystem.java:288)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.close(ZipFileSystem.java:287)
        at dotty.tools.io.JarArchive.close(JarArchive.scala:12)
        at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:71)
        at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:185)

Same with -YdisableFlatCpCaching.

Also leaves behind zipfstmp17716756326776923670.tmp on cygwin in cwd.

@smarter
Copy link
Member

smarter commented Dec 15, 2020

Porting these two PRs might help: scala/scala#7366, scala/scala#7644

@philwalk
Copy link
Contributor Author

@michelou
Sorry for the delay, I wasn't receiving notifications.
I discovered the problem using scalac shell script in cygwin bash environment.
I verified that the Problem doesn't occur in WSL bash environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants