#1208 BootEnv should use ext classloader

vkuzkokov Mon 13 Sep 2010

Consider 3rd party library on java:

package party3;

public class Marker
{
  public static Marker instance = new Marker(){ };
}

And Fantom pod using this library:

using [java]party3

class Main
{
  static Void main()
  {
    echo(Marker.instance.typeof->toClass->getSuperclass)
    // Any other code to check that library is found and loaded
    echo(Impl().typeof)
  }
}

class Impl : Marker
{
}

Put jar with library anywhere it will work (e.g. $FAN_HOME/lib/java/ext/), then build and run our pod (running as script doesn't make difference). What happens is:

class party3.Marker
sys::Err: Cannot map Fantom type to Java class: [java]party3::Marker
  fan.sys.JavaType.toClass (JavaType.java:127)
  fan.sys.JavaType.initSlots (JavaType.java:178)
  fan.sys.JavaType.slots (JavaType.java:91)
  fan.sys.ClassType.merge (ClassType.java:335)
  fan.sys.ClassType.doReflect (ClassType.java:289)
  fan.sys.ClassType.reflect (ClassType.java:258)
  fan.sys.ClassType.emit (ClassType.java:443)
  fan.sys.FanClassLoader.findFanClass (FanClassLoader.java:164)
  fan.sys.FanClassLoader.findClass (FanClassLoader.java:92)
  java.lang.ClassLoader.loadClass (ClassLoader.java:317)
  java.lang.ClassLoader.loadClass (ClassLoader.java:252)
  java.lang.ClassLoader.loadClassInternal (ClassLoader.java:375)
  test::Main.main (test.fan:8)
  java.lang.reflect.Method.invoke (Method.java:592)
  fan.sys.Method.invoke (Method.java:536)
  fan.sys.Method$MethodFunc.callList (Method.java:182)
  fan.sys.Method.callList (Method.java:147)
  fanx.tools.Fan.callMain (Fan.java:135)
  fanx.tools.Fan.executeType (Fan.java:102)
  fanx.tools.Fan.execute (Fan.java:38)
  1 More...
Cause:
  sys::Err: java.lang.ClassNotFoundException: party3.Marker
    java.net.URLClassLoader$1.run (URLClassLoader.java:200)
    java.security.AccessController.doPrivileged (AccessController.java)
    java.net.URLClassLoader.findClass (URLClassLoader.java:188)
    java.lang.ClassLoader.loadClass (ClassLoader.java:317)
    sun.misc.Launcher$AppClassLoader.loadClass (Launcher.java:280)
    java.lang.ClassLoader.loadClass (ClassLoader.java:252)
    java.lang.ClassLoader.loadClassInternal (ClassLoader.java:375)
    java.lang.Class.forName0 (Class.java)
    java.lang.Class.forName (Class.java:164)
    fan.sys.BootEnv.loadJavaClass (BootEnv.java:234)
    fan.sys.JavaType.toClass (JavaType.java:122)
    fan.sys.JavaType.initSlots (JavaType.java:178)
    fan.sys.JavaType.slots (JavaType.java:91)
    fan.sys.ClassType.merge (ClassType.java:335)
    fan.sys.ClassType.doReflect (ClassType.java:289)
    fan.sys.ClassType.reflect (ClassType.java:258)
    fan.sys.ClassType.emit (ClassType.java:443)
    fan.sys.FanClassLoader.findFanClass (FanClassLoader.java:164)
    fan.sys.FanClassLoader.findClass (FanClassLoader.java:92)
    java.lang.ClassLoader.loadClass (ClassLoader.java:317)
    16 More...

The first line in output class party3.Marker means that we called java.lang.Class.toString for the instance of Class representing party3.Marker. Many other things point out that class is loaded.

All in all, it's some ClassLoader issue that I didn't manage to track down. I bet it's some kind of bug.

brian Mon 13 Sep 2010

Promoted to ticket #1208 and assigned to brian

I can reproduce this problem following your instructions. I will take a look.

brian Mon 13 Sep 2010

Renamed from Implementing java classes to BootEnv should use ext classloader

brian Mon 13 Sep 2010

Ticket resolved in 1.0.55

I changed the BootEnv to use the ext classloader instead of just the system classloader. That fixes the test case you provided. Let me know if you see anything else fishy.

changeset

Login or Signup to reply.