Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Scala 2.9.1
    • Fix Version/s: None
    • Component/s: Misc Library
    • Labels:
      None
    • Environment:

      Mac OSX Leopard, Java 6

      Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-9M3425)
      Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)

      Description

      Platform.getClassForName fails to load a class if the code calling it is not compiled with the -optimize flag. It looks like a different classloader is used if the call occurs within the Platform object than when it is inlined. You can see difference if you compile the attached code w/o -optimize and compare the two stack traces.

        Activity

        Hide
        Christopher Vogt added a comment -

        I cannot reproduce this in Windows. Neither with 2.9.1 nor trunk. Can you try in Mac OS please?

        Regardless if -optimize is set or not, I always get:

        Foo
        Foo
        java.lang.ClassNotFoundException: sdf
                at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
                at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$findClass(ScalaClassLoader.scala:88)
                at scala.tools.nsc.util.ScalaClassLoader$class.findClass(ScalaClassLoader.scala:44)
                at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.findClass(ScalaClassLoader.scala:88)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$loadClass(ScalaClassLoader.scala:88)
                at scala.tools.nsc.util.ScalaClassLoader$class.loadClass(ScalaClassLoader.scala:50)
                at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.loadClass(ScalaClassLoader.scala:88)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
                at java.lang.Class.forName0(Native Method)
                at java.lang.Class.forName(Class.java:169)
                at TestClass$.main(TestCls.scala:16)
                at TestClass.main(TestCls.scala)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:597)
                at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:78)
                at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:24)
                at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:88)
                at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:78)
                at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
                at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33)
                at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40)
                at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:56)
                at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)
                at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
                at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
        
        Show
        Christopher Vogt added a comment - I cannot reproduce this in Windows. Neither with 2.9.1 nor trunk. Can you try in Mac OS please? Regardless if -optimize is set or not, I always get: Foo Foo java.lang.ClassNotFoundException: sdf at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$findClass(ScalaClassLoader.scala:88) at scala.tools.nsc.util.ScalaClassLoader$class.findClass(ScalaClassLoader.scala:44) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.findClass(ScalaClassLoader.scala:88) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$loadClass(ScalaClassLoader.scala:88) at scala.tools.nsc.util.ScalaClassLoader$class.loadClass(ScalaClassLoader.scala:50) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.loadClass(ScalaClassLoader.scala:88) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at TestClass$.main(TestCls.scala:16) at TestClass.main(TestCls.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:78) at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:24) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:88) at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:78) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33) at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40) at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:56) at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
        Hide
        Adriaan Moors added a comment -
        [adriaan@lampmac13 scala (topic/virtpatmat)]$ qsc -version
        Scala compiler version v2.10.0-M1-0177-g39dd0f7924-2012-02-14 -- Copyright 2002-2011, LAMP/EPFL
        
        [adriaan@lampmac13 scala (topic/virtpatmat)]$ qsc -optimize /Users/adriaan/Downloads/TestCls.scala 
        [adriaan@lampmac13 scala (topic/virtpatmat)]$ qs TestClass
        Foo
        Foo
        java.lang.ClassNotFoundException: sdf
        	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        	at java.security.AccessController.doPrivileged(Native Method)
        	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$findClass(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.util.ScalaClassLoader$class.findClass(ScalaClassLoader.scala:57)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.findClass(ScalaClassLoader.scala:159)
        	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$loadClass(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.util.ScalaClassLoader$class.loadClass(ScalaClassLoader.scala:63)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.loadClass(ScalaClassLoader.scala:159)
        	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        	at java.lang.Class.forName0(Native Method)
        	at java.lang.Class.forName(Class.java:169)
        	at TestClass$.main(TestCls.scala:16)
        	at TestClass.main(TestCls.scala)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        	at java.lang.reflect.Method.invoke(Method.java:597)
        	at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:90)
        	at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:38)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:90)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
        	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
        	at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
        	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
        	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
        	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92)
        	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
        	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
        

        cleaning class files just in case, then without optimize – different exception

        [adriaan@lampmac13 scala (topic/virtpatmat)]$ rm /tmp/*.class
        [adriaan@lampmac13 scala (topic/virtpatmat)]$ qs TestClass
        No such file or class on classpath: TestClass
        
        [adriaan@lampmac13 scala (topic/virtpatmat)]$ qsc /Users/adriaan/Downloads/TestCls.scala 
        [adriaan@lampmac13 scala (topic/virtpatmat)]$ qs TestClass
        java.lang.ClassNotFoundException: Foo
        	at java.lang.Class.forName0(Native Method)
        	at java.lang.Class.forName(Class.java:169)
        	at scala.compat.Platform$.getClassForName(Platform.scala:104)
        	at TestClass$.main(TestCls.scala:7)
        	at TestClass.main(TestCls.scala)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        	at java.lang.reflect.Method.invoke(Method.java:597)
        	at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:90)
        	at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:38)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:90)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
        	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
        	at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
        	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
        	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
        	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92)
        	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
        	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
        Foo
        java.lang.ClassNotFoundException: sdf
        	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        	at java.security.AccessController.doPrivileged(Native Method)
        	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$findClass(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.util.ScalaClassLoader$class.findClass(ScalaClassLoader.scala:57)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.findClass(ScalaClassLoader.scala:159)
        	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$loadClass(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.util.ScalaClassLoader$class.loadClass(ScalaClassLoader.scala:63)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.loadClass(ScalaClassLoader.scala:159)
        	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        	at java.lang.Class.forName0(Native Method)
        	at java.lang.Class.forName(Class.java:169)
        	at TestClass$.main(TestCls.scala:16)
        	at TestClass.main(TestCls.scala)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        	at java.lang.reflect.Method.invoke(Method.java:597)
        	at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:90)
        	at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:38)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:90)
        	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:159)
        	at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
        	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
        	at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
        	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
        	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
        	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92)
        	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
        	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
        
        Show
        Adriaan Moors added a comment - [adriaan@lampmac13 scala (topic/virtpatmat)]$ qsc -version Scala compiler version v2.10.0-M1-0177-g39dd0f7924-2012-02-14 -- Copyright 2002-2011, LAMP/EPFL [adriaan@lampmac13 scala (topic/virtpatmat)]$ qsc -optimize /Users/adriaan/Downloads/TestCls.scala [adriaan@lampmac13 scala (topic/virtpatmat)]$ qs TestClass Foo Foo java.lang.ClassNotFoundException: sdf at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$findClass(ScalaClassLoader.scala:159) at scala.tools.nsc.util.ScalaClassLoader$class.findClass(ScalaClassLoader.scala:57) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.findClass(ScalaClassLoader.scala:159) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$loadClass(ScalaClassLoader.scala:159) at scala.tools.nsc.util.ScalaClassLoader$class.loadClass(ScalaClassLoader.scala:63) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.loadClass(ScalaClassLoader.scala:159) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at TestClass$.main(TestCls.scala:16) at TestClass.main(TestCls.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:90) at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:38) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:159) at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:90) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:159) at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45) at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35) at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45) at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70) at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) cleaning class files just in case, then without optimize – different exception [adriaan@lampmac13 scala (topic/virtpatmat)]$ rm /tmp/*.class [adriaan@lampmac13 scala (topic/virtpatmat)]$ qs TestClass No such file or class on classpath: TestClass [adriaan@lampmac13 scala (topic/virtpatmat)]$ qsc /Users/adriaan/Downloads/TestCls.scala [adriaan@lampmac13 scala (topic/virtpatmat)]$ qs TestClass java.lang.ClassNotFoundException: Foo at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at scala.compat.Platform$.getClassForName(Platform.scala:104) at TestClass$.main(TestCls.scala:7) at TestClass.main(TestCls.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:90) at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:38) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:159) at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:90) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:159) at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45) at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35) at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45) at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70) at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) Foo java.lang.ClassNotFoundException: sdf at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$findClass(ScalaClassLoader.scala:159) at scala.tools.nsc.util.ScalaClassLoader$class.findClass(ScalaClassLoader.scala:57) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.findClass(ScalaClassLoader.scala:159) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$loadClass(ScalaClassLoader.scala:159) at scala.tools.nsc.util.ScalaClassLoader$class.loadClass(ScalaClassLoader.scala:63) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.loadClass(ScalaClassLoader.scala:159) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at TestClass$.main(TestCls.scala:16) at TestClass.main(TestCls.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:90) at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:38) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:159) at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:90) at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:159) at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28) at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45) at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35) at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45) at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70) at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92) at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101) at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
        Hide
        Vlad Ureche added a comment -

        Interesting: I can reproduce the bug running with scala, but running with java it always gives me:

        $ java -cp .:$SCALA_PACK/lib/scala-library.jar TestClass
        Foo
        Foo
        Exception in thread "main" java.lang.ClassNotFoundException: sdf
        [...]
        
        Show
        Vlad Ureche added a comment - Interesting: I can reproduce the bug running with scala, but running with java it always gives me: $ java -cp .:$SCALA_PACK/lib/scala-library.jar TestClass Foo Foo Exception in thread "main" java.lang.ClassNotFoundException: sdf [...]
        Hide
        Vlad Ureche added a comment -

        Classloader issue. This testcase shows the problem clearly:

        class Foo
        
        object TestClass {
          def main(args: Array[String]) {
        
            try {
              val cls = java.lang.Class.forName("Foo")
              println(cls.getName)
            } catch {
              case e => println(e)
            }
        
            try {
              val cls = scala.compat.Platform.getClassForName("Foo")
              println(cls.getName)
            } catch {
              case e => println(e)
            }
          }
        }
        
        $ rm -f *.class; scalac TestCls.scala
        $ scala TestClass
        Foo
        java.lang.ClassNotFoundException: Foo
        

        Yes, you're not dreaming, it says "ClassNotFoundException" after if it found and loaded Foo!

        Show
        Vlad Ureche added a comment - Classloader issue. This testcase shows the problem clearly: class Foo object TestClass { def main(args: Array[String]) { try { val cls = java.lang.Class.forName("Foo") println(cls.getName) } catch { case e => println(e) } try { val cls = scala.compat.Platform.getClassForName("Foo") println(cls.getName) } catch { case e => println(e) } } } $ rm -f *.class; scalac TestCls.scala $ scala TestClass Foo java.lang.ClassNotFoundException: Foo Yes, you're not dreaming, it says "ClassNotFoundException" after if it found and loaded Foo!
        Hide
        Adriaan Moors added a comment -

        Eugene, could you apply your recently acquired classloader-fu?

        Show
        Adriaan Moors added a comment - Eugene, could you apply your recently acquired classloader-fu?
        Hide
        Paul Phillips added a comment -

        It's the runner's usage of the boot classloader for speed.

        % scala3 TestClass
        Foo
        java.lang.ClassNotFoundException: Foo
        % scala3 -nobootcp TestClass
        Foo
        Foo
        

        The fact that it works under -optimise but fails without it highlights an interesting and heretofore unknown (at least, I've never heard anyone mention it) risk of inlining. If you inline code from one class into another class, and those classes wind up being loaded from different classloaders, you can change the meaning of the code. A call to Class.forName(name) will load from the classloader of the callee rather than the classloader of the caller.

        This means that the one-argument form of Class.forName must never be inlined; or it must first be expanded to the three argument form. I will open a separate ticket about this.

        Show
        Paul Phillips added a comment - It's the runner's usage of the boot classloader for speed. % scala3 TestClass Foo java.lang.ClassNotFoundException: Foo % scala3 -nobootcp TestClass Foo Foo The fact that it works under -optimise but fails without it highlights an interesting and heretofore unknown (at least, I've never heard anyone mention it) risk of inlining. If you inline code from one class into another class, and those classes wind up being loaded from different classloaders, you can change the meaning of the code. A call to Class.forName(name) will load from the classloader of the callee rather than the classloader of the caller. This means that the one-argument form of Class.forName must never be inlined; or it must first be expanded to the three argument form. I will open a separate ticket about this.
        Hide
        Paul Phillips added a comment -

        Opened SI-6789.

        Show
        Paul Phillips added a comment - Opened SI-6789 .

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Erik Engbrecht
          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:

              Development