Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4192120

Using rmi, cannot write strings longer than 64k-1.

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1
    • core-libs
    • generic
    • generic



      Name: clC74495 Date: 11/23/98


      This is releated to bug #4026823, which requested an exception when strings longer than 64k-1 were written.
      This fix was provided in DataOutputStream::writeUTF(). However, we believe this should be transparent to
      java programmer; in other words, rmi should break up the long strings rather than leave this to the user.
      If this is not possible, this restriction should be better documented.

      The following code reproduces this problem:

      RetString.java:
      ---------------------------------------------
      package foo;

      import java.rmi.*;
      import java.rmi.server.*;

      public interface RetString extends Remote
      {
              public String getString65535() throws RemoteException;
              public String getString65536() throws RemoteException;
      }
      ------------------------------------------------

      RetStringImpl.java:
      ------------------------------------------------
      package foo;

      import java.rmi.*;
      import java.rmi.server.*;
      import java.rmi.registry.LocateRegistry;

      public class RetStringImpl extends UnicastRemoteObject
              implements RetString
      {
              public static void main(String[] args)
              {
                      // set the security manager for the application
                      System.setSecurityManager(new RMISecurityManager());

                      // Create a new registry on the appropriate port
                      try {
                              LocateRegistry.createRegistry(portNum);
                      }
                      catch( Exception e ) {
                              System.err.println( "Failed to create registry : " + e )
      ;
                              System.exit(1);
                      }

                      // Export an instance of this object
                      try {
                              new RetStringImpl();
                      } catch (Exception e) {
                              System.out.println("Error creating exported object: " +
      e);
                              e.printStackTrace();
                      }
              }

              public RetStringImpl()
                      throws RemoteException
              {
                      /*
                       * Create string exactly 65535 bytes, done in 64 byte chunks
                       * for efficiency
                       */
                      for (int i=0 ; i<1023 ; i++) {
                              str = str + comp64chars;
                      }
                      str = str + comp63chars;
                      lessthan64k = str;
                      exactly64k = str + "*";

                      String url = "rmi://:"+portNum+"/RetString";
                      try {
                              Naming.rebind(url, this);
                      } catch (Exception e) {
                              System.out.println("Exception binding URL " + url);
                              e.printStackTrace();
                      }
                      System.out.println("Exported object created...");
              }

              public String getString65535()
                      throws RemoteException
              {
                      return lessthan64k;
              }

              public String getString65536()
                      throws RemoteException
              {
                      return exactly64k;
              }

              protected static String lessthan64k = "";
              protected static String exactly64k = "";
              protected static String str = "";
              protected static String comp64chars =
                      "***************************************************************
      *";
              protected static String comp63chars =
                      "***************************************************************
      ";
              protected static int portNum = 1200;
      }
      ---------------------------------------------------------

      Client.java:
      ---------------------------------------------------------
      package foo;

      import java.rmi.*;
      import java.rmi.server.*;

      public class Client
      {
              public static void main(String[] args)
              {
                      try {
                              RetString rs = (RetString) Naming.lookup(
                                      "rmi://localHost:1200/RetString");

                              String s = rs.getString65535();
                              System.out.println("Got string, length = " + s.length())
      ;
                              String s1 = rs.getString65536();
                              System.out.println("Got string, length = " + s1.length()
      );
                      } catch (Exception e) {
                              System.out.println("Ooops, got exception " + e.toString(
      ));
                              System.out.println("Stack trace:");
                              e.printStackTrace();
                      }
              }
      }
      --------------------------------------------------
      (Review ID: 43155)
      ======================================================================

            Unassigned Unassigned
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: