3 Replies Latest reply on Jan 22, 2003 4:15 PM by Peter Doornbosch

    EJB remote accesing case

    Julio Cesar Newbie

      I have the following case:
      Client Classes:
      - A

      Server Classes:
      - A
      - B (subclass of A )
      - MySessionBean

      this session bean has a method like this:

      public A doSomething(){
      ...//run tasks
      //got B
      return (A) B ;
      Ok. now,
      The problem is that, the RMI tries to send back an instance of B instead of A . And, since B is not present in the client distribution(and it is supposed not to be), the client throws the following exception:

      Caused by: java.lang.ClassNotFoundException: B
      (no security manager: RMI class loader disabled)
      at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:368)

      How would this problem be addressed?...

      thanks for your comments...


        • 1. Re: EJB remote accesing case
          Bernd Zeitler Expert


          IMHO, best practice should be to implement a method like this to B:
          A getSuperClone();

          returning a real instance of A.



          • 2. Re: EJB remote accesing case
            Julio Cesar Newbie

            I add a method to B, like this:

            public A getSuperClone(){

            return (A) super.clone();

            and in the session bean.

            public A doSomething(){

            return B.getSuperClone();

            BUT, still the RMI is sending back an instance of B.
            I don't understand this behavior. I think RMI should marshall the object as A not as B. Is it a java RMI hole? or JBoss Hole?

            comments welcomed.


            • 3. Re: EJB remote accesing case
              Peter Doornbosch Apprentice

              clone() always gives a clone of the original object; casting can't fool the runtime system. So your method getSuperClone() still returns a B (put a of println(super.clone()); in your method and you'll see).

              So what you have to is what the other reply suggested: create a _new_ A and return that one:
              public A getSuperClone()
              A copy = new A();
              A.setX = this.getX();
              // etc.
              return copy;