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

Backport tools.jar robustness for REPL, fail loud

    Details

      Description

      After launching the REPL from sbt, the :javap command does not work for class names:

      scala> :javap iControl.services.CommonIPPortDefinition

      scala> :javap iControl.services.CommonIPPortDefinition

      scala> :javap java.lang.Object

        Activity

        Hide
        Robin Green added a comment -

        Scala 2.9.1 prints:

        :javap unavailable on this platform.
        
        Show
        Robin Green added a comment - Scala 2.9.1 prints: :javap unavailable on this platform.
        Hide
        Robin Green added a comment -

        Workaround:

        scala -toolcp /usr/lib/jvm/jdk1.6.0_32/lib/tools.jar
        

        However, it doesn't look like I can use this workaround from sbt.

        Show
        Robin Green added a comment - Workaround: scala -toolcp /usr/lib/jvm/jdk1.6.0_32/lib/tools.jar However, it doesn't look like I can use this workaround from sbt.
        Hide
        A. P. Marki added a comment -

        IIUC, this is a request to backport a fix in 2.10 to search for tools.jar.

        IOW, this works in 2.10, and "affects versions" is only 2.9.

        https://github.com/scala/scala/blob/v2.10.2/src/compiler/scala/tools/nsc/interpreter/ILoop.scala#L376

        Show
        A. P. Marki added a comment - IIUC, this is a request to backport a fix in 2.10 to search for tools.jar. IOW, this works in 2.10, and "affects versions" is only 2.9. https://github.com/scala/scala/blob/v2.10.2/src/compiler/scala/tools/nsc/interpreter/ILoop.scala#L376
        Hide
        Robin Green added a comment -

        No, it doesn't work in 2.10. The command prints nothing. In Scala 2.9, it at least prints an error message, but it doesn't find the tools.jar in either version.

        Show
        Robin Green added a comment - No, it doesn't work in 2.10. The command prints nothing. In Scala 2.9, it at least prints an error message, but it doesn't find the tools.jar in either version.
        Hide
        A. P. Marki added a comment -

        I left my comfort zone and got the versions aligned, but alas IWFM on 2.10.

        There was an enhancement for 2.11:

        https://issues.scala-lang.org/browse/SI-7410

        On Ubuntu it's easy to get JAVA_HOME, java and javac at cross-purposes. In my case, after installing jdk7, it left java at java6. I've forgotten the details except that it was a confusing mode of failure; perhaps it's more confusing on 2.10.

        apm@mara:~/tmp/q$ JAVA_HOME=$JAVA6_HOME sbt12
        [info] Set current project to default-7bbd7f (in build file:/home/apm/tmp/q/)
        > ++ 2.10.2
        Setting version to 2.10.2
        [info] Set current project to default-7bbd7f (in build file:/home/apm/tmp/q/)
        > console
        [info] Updating {file:/home/apm/tmp/q/}default-7bbd7f...
        [info] Resolving org.scala-lang#scala-library;2.10.2 ...
        [info] Done updating.
        [info] 'compiler-interface' not yet compiled for Scala 2.10.2. Compiling...
        [info]   Compilation completed in 12.899 s
        [info] Starting scala interpreter...
        [info] 
        Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.6.0_27).
        Type in expressions to have them evaluated.
        Type :help for more information.
        
        scala> :javap
        :javap [-lcsvp] [path1 path2 ...]
        
        scala> :javap -public scala.Option
        Compiled from "Option.scala"
        

        I see there's an about command:

        > about
        [info] This is sbt 0.12.3
        [info] The current project is {file:/home/apm/tmp/q/}default-7bbd7f
        [info] The current project is built against Scala 2.10.2
        [info] 
        [info] sbt, sbt plugins, and build definitions are using Scala 2.9.2
        > 
        

        There's a debug flag that might help. But what does this mean?

        $ sbt12 -Dscala.repl.debug=true
        
        Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_25).
        Type in expressions to have them evaluated.
        Type :help for more information.
        [info] started at Thu Aug 29 11:21:32 PDT 2013
        
        scala> :javap
        :javap unavailable: no tools.jar at /usr/lib/jvm/java-7-openjdk-amd64
        :javap not yet working with java 1.7
        

        Not finding tools.jar should be a spurious report.

        Running that again with JDK 6 works as expected:

        Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.6.0_27).
        Type in expressions to have them evaluated.
        Type :help for more information.
        [info] started at Thu Aug 29 11:28:58 PDT 2013
        
        scala> :javap
        :javap available.
        :javap [-lcsvp] [path1 path2 ...]
        
        scala> :javap java.lang.Object
        Compiled from "Object.java"
        

        Also, under debug,

        > about
        [info] This is sbt 0.12.3
        [info] The current project is {file:/home/apm/tmp/q/}default-7bbd7f
        [info] The current project is built against Scala 2.9.2
        [info] 
        [info] sbt, sbt plugins, and build definitions are using Scala 2.9.2
        > console
        [info] Starting scala interpreter...
        [info] 
        [error] (run-main) java.lang.NullPointerException
        java.lang.NullPointerException
        	at scala.tools.nsc.interpreter.ILoop.<init>(ILoop.scala:68)
        	at scala.tools.nsc.InterpreterLoop.<init>(InterpreterLoop.scala:9)
        	at scala.tools.nsc.InterpreterLoop.<init>(InterpreterLoop.scala:11)
        	at xsbt.ConsoleInterface$$anon$1.<init>(ConsoleInterface.scala:27)
        	at xsbt.ConsoleInterface.run(ConsoleInterface.scala:27)
        
        Show
        A. P. Marki added a comment - I left my comfort zone and got the versions aligned, but alas IWFM on 2.10. There was an enhancement for 2.11: https://issues.scala-lang.org/browse/SI-7410 On Ubuntu it's easy to get JAVA_HOME, java and javac at cross-purposes. In my case, after installing jdk7, it left java at java6. I've forgotten the details except that it was a confusing mode of failure; perhaps it's more confusing on 2.10. apm@mara:~/tmp/q$ JAVA_HOME=$JAVA6_HOME sbt12 [info] Set current project to default-7bbd7f (in build file:/home/apm/tmp/q/) > ++ 2.10.2 Setting version to 2.10.2 [info] Set current project to default-7bbd7f (in build file:/home/apm/tmp/q/) > console [info] Updating {file:/home/apm/tmp/q/}default-7bbd7f... [info] Resolving org.scala-lang#scala-library;2.10.2 ... [info] Done updating. [info] 'compiler-interface' not yet compiled for Scala 2.10.2. Compiling... [info] Compilation completed in 12.899 s [info] Starting scala interpreter... [info] Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.6.0_27). Type in expressions to have them evaluated. Type :help for more information. scala> :javap :javap [-lcsvp] [path1 path2 ...] scala> :javap -public scala.Option Compiled from "Option.scala" I see there's an about command: > about [info] This is sbt 0.12.3 [info] The current project is {file:/home/apm/tmp/q/}default-7bbd7f [info] The current project is built against Scala 2.10.2 [info] [info] sbt, sbt plugins, and build definitions are using Scala 2.9.2 > There's a debug flag that might help. But what does this mean? $ sbt12 -Dscala.repl.debug=true Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_25). Type in expressions to have them evaluated. Type :help for more information. [info] started at Thu Aug 29 11:21:32 PDT 2013 scala> :javap :javap unavailable: no tools.jar at /usr/lib/jvm/java-7-openjdk-amd64 :javap not yet working with java 1.7 Not finding tools.jar should be a spurious report. Running that again with JDK 6 works as expected: Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.6.0_27). Type in expressions to have them evaluated. Type :help for more information. [info] started at Thu Aug 29 11:28:58 PDT 2013 scala> :javap :javap available. :javap [-lcsvp] [path1 path2 ...] scala> :javap java.lang.Object Compiled from "Object.java" Also, under debug, > about [info] This is sbt 0.12.3 [info] The current project is {file:/home/apm/tmp/q/}default-7bbd7f [info] The current project is built against Scala 2.9.2 [info] [info] sbt, sbt plugins, and build definitions are using Scala 2.9.2 > console [info] Starting scala interpreter... [info] [error] (run-main) java.lang.NullPointerException java.lang.NullPointerException at scala.tools.nsc.interpreter.ILoop.<init>(ILoop.scala:68) at scala.tools.nsc.InterpreterLoop.<init>(InterpreterLoop.scala:9) at scala.tools.nsc.InterpreterLoop.<init>(InterpreterLoop.scala:11) at xsbt.ConsoleInterface$$anon$1.<init>(ConsoleInterface.scala:27) at xsbt.ConsoleInterface.run(ConsoleInterface.scala:27)
        Hide
        A. P. Marki added a comment -

        Yes, that seems to be the problem, viz, java and JAVA_HOME do not jibe.

        I was able to test this way, without munging my environment, thankfully. This is java at v6 and JAVA_HOME at v7; reflective invocation of javap finds the wrong tools.jar.

        apm@mara:~/tmp/q$ JAVACMD=$JAVA6_HOME/bin/java JAVA_HOME=$JAVA7_HOME sbt12 
        Launching with /home/apm/bin/sbt-0.12.3/bin/sbt-launch.jar
        [info] Set current project to default-7bbd7f (in build file:/home/apm/tmp/q/)
        > 
        > ++ 2.10.2
        Setting version to 2.10.2
        [info] Set current project to default-7bbd7f (in build file:/home/apm/tmp/q/)
        > 
        > about
        [info] This is sbt 0.12.3
        [info] The current project is {file:/home/apm/tmp/q/}default-7bbd7f
        [info] The current project is built against Scala 2.10.2
        [info] 
        [info] sbt, sbt plugins, and build definitions are using Scala 2.9.2
        > console
        [info] Starting scala interpreter...
        [info] 
        Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.6.0_27).
        Type in expressions to have them evaluated.
        Type :help for more information.
        
        scala> :javap
        :javap [-lcsvp] [path1 path2 ...]
        
        scala> :javap java.lang.Object
        
        scala> 
        

        It does indeed fail silently. Boy, that's confusing.

        Show
        A. P. Marki added a comment - Yes, that seems to be the problem, viz, java and JAVA_HOME do not jibe. I was able to test this way, without munging my environment, thankfully. This is java at v6 and JAVA_HOME at v7; reflective invocation of javap finds the wrong tools.jar. apm@mara:~/tmp/q$ JAVACMD=$JAVA6_HOME/bin/java JAVA_HOME=$JAVA7_HOME sbt12 Launching with /home/apm/bin/sbt-0.12.3/bin/sbt-launch.jar [info] Set current project to default-7bbd7f (in build file:/home/apm/tmp/q/) > > ++ 2.10.2 Setting version to 2.10.2 [info] Set current project to default-7bbd7f (in build file:/home/apm/tmp/q/) > > about [info] This is sbt 0.12.3 [info] The current project is {file:/home/apm/tmp/q/}default-7bbd7f [info] The current project is built against Scala 2.10.2 [info] [info] sbt, sbt plugins, and build definitions are using Scala 2.9.2 > console [info] Starting scala interpreter... [info] Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.6.0_27). Type in expressions to have them evaluated. Type :help for more information. scala> :javap :javap [-lcsvp] [path1 path2 ...] scala> :javap java.lang.Object scala> It does indeed fail silently. Boy, that's confusing.
        Hide
        A. P. Marki added a comment -

        Let it never be said that :javap command does nothing.

        https://github.com/scala/scala/pull/2895

        Show
        A. P. Marki added a comment - Let it never be said that :javap command does nothing. https://github.com/scala/scala/pull/2895

          People

          • Assignee:
            A. P. Marki
            Reporter:
            Robin Green
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development