Skip to content

single wildcard classpath entry in Windows gets globbed in dist/bin/scala #13618

Closed
@philwalk

Description

@philwalk

Compiler version

Scala code runner version 3.1.1-RC1-bin-SNAPSHOT-git-3f978b3 -- Copyright 2002-2021, LAMP/EPFL

Minimized code

Here's the bug and the one-line fix.

On line 108 of MainGenericRunner:

      val globdir = cp.replaceAll("[\\/][^\\/]*$", "") // slash/backslash agnostic

the regex should have quadruple backslashes, like this:

      val globdir = cp.replaceAll("[\\\\/][^\\\\/]*$", "") // slash/backslash agnostic

The following script fails to compile without the fix:

#!bin/scala -classpath 'dist/target/pack/lib/*'

// import won't compile unless the hashbang line is effective in setting the classpath
import org.jline.terminal.Terminal

def main(args: Array[String]) =
  val cp = sys.props("java.class.path")
  printf("unglobbed classpath:\n%s\n", cp)

Added a test to verify this fix in dotty.tools.scripting.ClasspathTests

Output

Because the wildcard classpath is explanded by dist/bin/scala, only the first jar in the glob expansion becomes the classpath entry, and all others are added as command line arguments (jar files are intepreted by compiler as scala sources).
The attempt to run the script results in 456763 lines of error messages. Here are the last few lines:

-------------------------------------------------------------------------
3917 |vRH�����֍Yݘ��􃎃1���Dw���(PxNa��Q	0QNT=���`NŔqv:HE˧��)nYh&��(vt���μc8}����yDr��h՞��hLמ���~�)����QVa��ʕ1��iFy\���BX�*��Y͠B[��pDl!�ѣX
     |^
     |Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:6246:0 ----------------------------------------------------------------------------------------------------------------------------------------------
6246 |��*�n��@�0gb���ΛT���,"�zG�0���Q�-
     |^
     |Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:14210:0 ---------------------------------------------------------------------------------------------------------------------------------------------
14210 |��(��"~A+
      |^
      |Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:16269:0 ---------------------------------------------------------------------------------------------------------------------------------------------
16269 |��UκCgъ��[<NH��pUo����dTTڬ{J,x
      |^
      |Line is indented too far to the left, or a `}` is missing
7 warnings found
114151 errors found
Error: Errors encountered during compilation

Expectation

Script should run without error, printing something like the following:

unglobbed classpath: C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala-library-2.13.6.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-library_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala-asm-9.1.0-scala-1.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/compiler-interface-1.3.5.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-interfaces-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-compiler_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/tasty-core_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-staging_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-tasty-inspector_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-reader-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-terminal-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-terminal-jna-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jna-5.3.1.jar;;

The fix plus unit tests to verify it will be submitted as a PR very soon.

NOTE: the reason the error is specific to Windows is due to the fact that the half-quotes surrounding the wildcard classpath in the hashbang line of the script prevent globbing in Linux and other environments, but not in Windows.

In the scala3-3.0.2 release (and earlier), this bug was fixed by appending a semicolon to wildcard classpath arguments.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions