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)
======================================================================
- duplicates
-
JDK-4026823 writeUTF OutputStream doesn't throw an exception when encoding > 65536
- Closed