Scala Programming Language
  1. Scala Programming Language
  2. SI-5528

scala runner puts . into class path implicitly

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.1
    • Fix Version/s: Scala 2.10.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Solaris 5.10 (x86)
      Java 1.6.0
      Scala 2.9.1

      Description

      If you specify the class path using -cp, scala
      will nonetheless use "." to get class files if they are there.
      I have a simple test case with a JAR file with the results of compiling
      two Scala files that print #1 when invoked. The #2 versions are the
      same but print #2. If I execute "scala -cp <JARFILE>" in the directory
      with the compiled versions of the #2 files, it gets those rather than the
      ones from the JAR files: . takes precedence over the class path.
      I unset the CLASSPATH environment variable.

      I suspected a java bug, but I have been unable to duplicate a Java only
      situation. It may have something to do with the very large number of
      JAR files passed to -Xbootclasspath/a in scala 2.9.1

      Workaround: use the -nobootcp option.

      See the following script.

      pabst.cs 593 % cat Test.scala
      object Test {
         var f : Foo = new Foo()
         def main(s : Array[String]) : Unit = { println("Test #2"); }
      }
      pabst.cs 594 % cat Foo.scala
      class Foo() {
        { println("Foo #2"); }
      }
      pabst.cs 595 % ls
      Foo.class    Foo.scala    Test$.class  Test.class   Test.scala
      pabst.cs 596 % scala -cp ../src1/one.jar Test
      Foo #2
      Test #2
      pabst.cs 597 % \rm *.class
      pabst.cs 598 % scala -cp ../src1/one.jar Test
      Foo #1
      Test #1
      pabst.cs 599 % java -version
      java version "1.6.0_05"
      Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
      Java HotSpot(TM) Server VM (build 10.0-b19, mixed mode)
      pabst.cs 600 % scala -version
      Scala code runner version 2.9.1.final -- Copyright 2002-2011, LAMP/EPFL
      pabst.cs 601 % more ~/.profile
      user=boyland
      pabst.cs 602 % uname -a
      SunOS pabst.cs.uwm.edu 5.10 Generic_141445-09 i86pc i386 i86pc
      pabst.cs 603 % echo $CLASSPATH
      CLASSPATH: Undefined variable
      pabst.cs 604 % scalac *.scala
      pabst.cs 605 % scala -cp ../src1/one.jar Test
      Foo #2
      Test #2
      pabst.cs 606 % scala -nobootcp -cp ../src1/one.jar Test
      Foo #1
      Test #1
      

        Activity

        Hide
        Daniel Spiewak added a comment -

        Reproduced locally with 2.9.1 and with an oldish build of 2.10. Note that there are a couple steps not given in the bug report. Namely, creating the one.jar with the modified files. In any case, the bug is clear.

        Show
        Daniel Spiewak added a comment - Reproduced locally with 2.9.1 and with an oldish build of 2.10. Note that there are a couple steps not given in the bug report. Namely, creating the one.jar with the modified files. In any case, the bug is clear.
        Hide
        John Tang Boyland added a comment -

        Reproduced on MacOSX 10 SnowLeopard.
        The bug does not exist in scala 2.7.7

        Show
        John Tang Boyland added a comment - Reproduced on MacOSX 10 SnowLeopard. The bug does not exist in scala 2.7.7
        Hide
        Paul Phillips added a comment -

        That was confusing. It is java sneaking up through the back door: by putting the scala libs on the bootclasspath, we end up not specifying a classpath to java at all, which proceeds to include ".", which we then propagate forward from java.class.path thinking the user set it.

        Show
        Paul Phillips added a comment - That was confusing. It is java sneaking up through the back door: by putting the scala libs on the bootclasspath, we end up not specifying a classpath to java at all, which proceeds to include ".", which we then propagate forward from java.class.path thinking the user set it.
        Hide
        Paul Phillips added a comment -

        07ffa8d66d

        Show
        Paul Phillips added a comment - 07ffa8d66d
        Hide
        John Tang Boyland added a comment -

        Paul, thanks for the quick fix. Can you describe the change you do, presumably in the "scala" command script?
        That would make it easier for me to fix my current configuration.

        Show
        John Tang Boyland added a comment - Paul, thanks for the quick fix. Can you describe the change you do, presumably in the "scala" command script? That would make it easier for me to fix my current configuration.
        Hide
        Paul Phillips added a comment - - edited

        Here's the diff:

        -    echo "-Xbootclasspath/a:$TOOL_CLASSPATH"
        +    echo "-Xbootclasspath/a:$TOOL_CLASSPATH -classpath \"\""
        
        Show
        Paul Phillips added a comment - - edited Here's the diff: - echo "-Xbootclasspath/a:$TOOL_CLASSPATH" + echo "-Xbootclasspath/a:$TOOL_CLASSPATH -classpath \"\""
        Hide
        John Tang Boyland added a comment -

        Thanks for the diff. It doesn't seem to apply to Scala 2.9.1. Here's a patch that seems to work for me:

        *** scala       Mon Aug 29 11:44:19 2011
        --- scala.fixed Tue Feb 28 14:18:48 2012
        ***************
        *** 111,116 ****
        --- 111,117 ----
        
          # default to the boot classpath for speed.
          CPSELECT="-Xbootclasspath/a:"
        + CPCLEAR="-classpath \"\""
        
          while [ $# -gt 0 ]; do
            case "$1" in
        ***************
        *** 134,139 ****
        --- 135,141 ----
                ;;
              -nobootcp)
                CPSELECT="-classpath "
        +       CPCLEAR=""
                shift
                ;;
              *)
        ***************
        *** 153,159 ****
          "${JAVACMD:=java}" \
            $JAVA_OPTS \
            "${java_args[@]}" \
        !   ${CPSELECT}${TOOL_CLASSPATH} \
            -Dscala.usejavacp=true \
            -Dscala.home="$SCALA_HOME" \
            -Denv.emacs="$EMACS" \
        --- 155,161 ----
          "${JAVACMD:=java}" \
            $JAVA_OPTS \
            "${java_args[@]}" \
        !   ${CPSELECT}${TOOL_CLASSPATH} ${CPCLEAR}\
            -Dscala.usejavacp=true \
            -Dscala.home="$SCALA_HOME" \
            -Denv.emacs="$EMACS" \
        
        Show
        John Tang Boyland added a comment - Thanks for the diff. It doesn't seem to apply to Scala 2.9.1. Here's a patch that seems to work for me: *** scala Mon Aug 29 11:44:19 2011 --- scala.fixed Tue Feb 28 14:18:48 2012 *************** *** 111,116 **** --- 111,117 ---- # default to the boot classpath for speed. CPSELECT="-Xbootclasspath/a:" + CPCLEAR="-classpath \"\"" while [ $# -gt 0 ]; do case "$1" in *************** *** 134,139 **** --- 135,141 ---- ;; -nobootcp) CPSELECT="-classpath " + CPCLEAR="" shift ;; *) *************** *** 153,159 **** "${JAVACMD:=java}" \ $JAVA_OPTS \ "${java_args[@]}" \ ! ${CPSELECT}${TOOL_CLASSPATH} \ -Dscala.usejavacp=true \ -Dscala.home="$SCALA_HOME" \ -Denv.emacs="$EMACS" \ --- 155,161 ---- "${JAVACMD:=java}" \ $JAVA_OPTS \ "${java_args[@]}" \ ! ${CPSELECT}${TOOL_CLASSPATH} ${CPCLEAR}\ -Dscala.usejavacp=true \ -Dscala.home="$SCALA_HOME" \ -Denv.emacs="$EMACS" \

          People

          • Assignee:
            Paul Phillips
            Reporter:
            John Tang Boyland
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development