Skip to content
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

scala runner puts . into class path implicitly #5528

Closed
scabug opened this issue Feb 27, 2012 · 8 comments
Closed

scala runner puts . into class path implicitly #5528

scabug opened this issue Feb 27, 2012 · 8 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Feb 27, 2012

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 " 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
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 27, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5528?orig=1
Reporter: John Tang Boyland (john.boyland)
Affected Versions: 2.9.1

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 27, 2012

@djspiewak said:
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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 27, 2012

John Tang Boyland (john.boyland) said:
Reproduced on MacOSX 10 SnowLeopard.
The bug does not exist in scala 2.7.7

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 28, 2012

@paulp said:
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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 28, 2012

@paulp said:
07ffa8d66d

@scabug scabug closed this Feb 28, 2012
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 28, 2012

John Tang Boyland (john.boyland) said:
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.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 28, 2012

@paulp said (edited on Feb 28, 2012 3:44:36 AM UTC):
Here's the diff:

-    echo "-Xbootclasspath/a:$TOOL_CLASSPATH"
+    echo "-Xbootclasspath/a:$TOOL_CLASSPATH -classpath \"\""
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Feb 28, 2012

John Tang Boyland (john.boyland) said:
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" \
@scabug scabug added this to the 2.10.0 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.