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

-J options are erroneously passed as arguments to the program #5019

Closed
scabug opened this issue Sep 21, 2011 · 6 comments
Closed

-J options are erroneously passed as arguments to the program #5019

scabug opened this issue Sep 21, 2011 · 6 comments

Comments

@scabug
Copy link

scabug commented Sep 21, 2011

When I pass a -Jfoo argument to the scala command, I would expect foo to be passed to the java command, and for -Jfoo to not be included in the list of arguments passed to my main function, as they are explicitly for the Java runtime and not my program. However, any -J arguments are included.

This behaviour is due to https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/src/compiler/scala/tools/ant/templates/tool-unix.tmpl#L129.

The problem really is that when you run a command such as

scala -Jfoo Bar

the Java command that is finally run is

java ... scala.tools.nsc.MainGenericRunner -Jfoo Bar

This means that scala.tools.nsc.MainGenericRunner tries to run the class -Jfoo with the argument Bar, and obviously fails to find the class.

Also, -J isn't documented in the manual page. The related option -D is documented.

This is possibly related to #4907.

@scabug
Copy link
Author

scabug commented Sep 21, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5019?orig=1
Reporter: Chris Seaton (chrisseaton)
Affected Versions: 2.9.1, 2.9.2
See #4907

@scabug
Copy link
Author

scabug commented Sep 21, 2011

@paulp said:
If you have witnessed it attempting to treat the -J argument like a class to run then you had better give me a transcript, because that's not what happens. And if you read the source to the runner you will see why it passes it.

@scabug
Copy link
Author

scabug commented Sep 21, 2011

Chris Seaton (chrisseaton) said (edited on Sep 21, 2011 11:18:44 PM UTC):
Using HelloWorld.scala from http://www.scala-lang.org/node/166.

$scala HelloWorld
Hello, world!
$scala -J-Xmx256M HelloWorld
java.lang.ClassNotFoundException 
 - klass: 'java/lang/ClassNotFoundException'
$scala HelloWorld -J-Xmx256M
java.lang.ClassNotFoundException 
 - klass: 'java/lang/ClassNotFoundException'

I presume that the ClassNotFoundException is -J-Xmx256M, but actually I may be mistaken about that.

I am using JAVA_OPTS as a workaround.

Edit: I meant HelloWorld, not Test in command lines above.

@scabug
Copy link
Author

scabug commented Sep 21, 2011

Chris Seaton (chrisseaton) said:
As an aside, looking at scala -help I can see that the format is

scala <options> [<script|class|object|jar> <arguments>]

However, if I run

scala HelloWorld -J-help

Then the scala script is treating -J-help as an option, when according to the usage grammar, it should be treating it as an argument and shouldn't be doing anything with it apart from passing it to main, so there is definitely something not right with the script.

@scabug
Copy link
Author

scabug commented Sep 22, 2011

@paulp said:

% cat a.scala
object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
}
% scalac291 a.scala 
% scala291 -J-Xmx256M HelloWorld
Hello, world!

You'll have to supply evidence it's not something in your environment.

There is a bug, which is that "scala HelloWorld -J-help" should be passing -J-help to HelloWorld rather than grabbing it for the JVM.

@scabug
Copy link
Author

scabug commented Dec 19, 2014

Viacheslav Blinov (dant3) said:
Can't reproduce with scala 2.11.4 on Mac OS X 10.10, and according to #4907 and scala/scala#2767 it looks like it was already fixed.

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

1 participant