[Q] StreamCorruptedException

Hello,
I'm using a simple EJB 2.0 bean with a findByPrimaryKey() method.
A piece of the stack trace is:
javax.ejb.FinderException: Exception raised in findByPrimaryKey
java.io.StreamCorruptedException: InputStream does not contain a serialized
object
java.io.StreamCorruptedException: InputStream does not contain a serialized
object
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:849)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
at
weblogic.ejb20.cmp.rdbms.RDBMSObjectInputStream.<init>(RDBMSObjectInputStream.java:15)
I know what this means, but I'm wondering if anyone knows under what
circumstances this happens?
Thanks.

Arg. Nevermind.
I am porting a project from another app server that lets you use
references to other beans to set attributes of the current bean -
and this is done automatically. The problem was WLS was trying to
serialize the other bean reference. The solution was to provide
the indirection by hand and get/set the correct attribute (String).

Similar Messages

  • StreamCorruptedException: does not contain a serialized object?

    Can someone tell me why am I getting this exception:
    C:\javapr>java FetchObject
    Couldn't retrieve binary data: java.io.StreamCorruptedException: InputStream
    does not contain a serialized object
    java.io.StreamCorruptedException: InputStream does
    not contain a serialized object
    at java.io.ObjectInputStream.readStreamHeader
    (ObjectInputStream.java:849)
    at java.io.ObjectInputStream.<init>
    (ObjectInputStream.java:168)
    at FetchObject.main(FetchObject.java:23)
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    class FetchObject implements Serializable {
        public static void main (String[] args) {
            try {
                String driver = "oracle.jdbc.driver.OracleDriver";
                Class.forName(driver);
                String url = "jdbc:oracle:thin:@mymachine:1521:homedeva";
                Connection conn = DriverManager.getConnection(url,"cnn","cnn");
                FetchObject i = new FetchObject();
                    // Select related
                    try
                         byte[] recdBlob = i.selectBlob( 1 , conn ); 
                         ByteArrayInputStream bytes = new ByteArrayInputStream(recdBlob);
                         ObjectInputStream deserialize = new ObjectInputStream( bytes );
              Employee x = (Employee)deserialize.readObject();
                    catch( Exception ex )
                  System.err.println("Couldn't retrieve binary data: " + ex);
                  ex.printStackTrace();
         catch( Exception ex )
              ex.printStackTrace();
        public byte[] selectBlob( int id, Connection conn )
         byte[] returndata = null;
         try
              Statement stmt = conn.createStatement();
              String sql = "SELECT id, rowdata FROM blobs WHERE id = " + id;
              ResultSet rs = stmt.executeQuery(sql);
              if ( rs.next() )
                           try
                               ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
                               BufferedInputStream bis = new BufferedInputStream( rs.getBinaryStream("rowdata") );
                             byte[] bindata = new byte[4096];
                               int bytesread = 0;
                               if ( !rs.wasNull() )
                                       if ( (bytesread = bis.read(bindata,0,bindata.length)) != -1 )
                                          baos.write(bindata,0,bytesread);
                                returndata = baos.toByteArray();
                             baos.flush();
                                bis.close();
                       catch ( Exception ex )
                            System.err.println("Problem retrieving binary data: " + ex);
                        rs.close();
                         stmt.close();  
               catch ( Exception ex )
                    System.err.println("Couldn't retrieve binary data: " + ex);
            return returndata;
    import java.io.*;
    class Employee implements Serializable
         private String lastName;
         private String firstName;
         public Employee(String lastName, String firstName)
              this.lastName = lastName; 
              this.firstName = firstName;
    }

    To clarify I have stored an Employee Object as a Blob in the Oracle database and am attempting to retreive the
    Employee Object from this Blob.
    Thanks

  • Java.io.StreamCorruptedException: InputStream does not contain a serialized object

              I have an applet which calls a JSP to write data object to the db and then the
              JSP sends back the updated data object. The writing part is ok but the response
              is giving the following error. The data object is in a separate class which implements
              Serialized.
              Here's the code in the applet calling the JSP and the response from the JSP
              URL server = null;
              String urlConnectionString = "http://localhost:7001/isLoginValid.jsp";
              try
              server = new URL(urlConnectionString);
              catch(MalformedURLException e)
              System.out.println("URL exception: " + e );
              // send request
              ObjectInputStream response = null;
              Object result = null;
              try
              URLConnection conn = server.openConnection();
              conn.setDoOutput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "application/octet-stream");
              ObjectOutputStream request = new ObjectOutputStream(new
              BufferedOutputStream(conn.getOutputStream()));
              request.writeObject((Object)dvo);
              request.flush();
              request.close();
              // get the result input stream
              response = new ObjectInputStream(new BufferedInputStream
              (conn.getInputStream()));
              // read response back from the server
              result = response.readObject();
              if( result!=null && (result instanceof DataVO))
              dvo = (DataVO)result;
              String vo = dvo.printDataVO();
              System.out.println("*DataVO*\n"+vo);
              else
              System.out.println("not an instanceof DataVO");
              catch(IOException ignored)
              System.out.println("Error in DataVO response");
              ignored.printStackTrace();
              Here's the code in the JSP sending the response back to the applet. The 'dvo'
              object is the object which is serialized and has gets and sets for the diff. data
              elements. When I print the 'dvo' before writing the object to outputStream it
              prints the correct values for the data element.
              // send response
              response.setStatus(HttpServletResponse.SC_OK);
              ObjectOutputStream outputStream = new ObjectOutputStream (new BufferedOutputStream
              (response.getOutputStream()));
              outputStream.writeObject(dvo);
              outputStream.flush();
              ERROR is as follows:
              Error in DataVO response
              java.io.StreamCorruptedException: InputStream does not contain a serialized object
              at java/io/ObjectInputStream.readStreamHeader
              at java/io/ObjectInputStream.<init>
              What am I doing wrong?. Please respond soon. The applet is run on IIS and the
              JSP in on weblogic 6.1. I'm not sure if that makes any difference.
              

              I have an applet which calls a JSP to write data object to the db and then the
              JSP sends back the updated data object. The writing part is ok but the response
              is giving the following error. The data object is in a separate class which implements
              Serialized.
              Here's the code in the applet calling the JSP and the response from the JSP
              URL server = null;
              String urlConnectionString = "http://localhost:7001/isLoginValid.jsp";
              try
              server = new URL(urlConnectionString);
              catch(MalformedURLException e)
              System.out.println("URL exception: " + e );
              // send request
              ObjectInputStream response = null;
              Object result = null;
              try
              URLConnection conn = server.openConnection();
              conn.setDoOutput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "application/octet-stream");
              ObjectOutputStream request = new ObjectOutputStream(new
              BufferedOutputStream(conn.getOutputStream()));
              request.writeObject((Object)dvo);
              request.flush();
              request.close();
              // get the result input stream
              response = new ObjectInputStream(new BufferedInputStream
              (conn.getInputStream()));
              // read response back from the server
              result = response.readObject();
              if( result!=null && (result instanceof DataVO))
              dvo = (DataVO)result;
              String vo = dvo.printDataVO();
              System.out.println("*DataVO*\n"+vo);
              else
              System.out.println("not an instanceof DataVO");
              catch(IOException ignored)
              System.out.println("Error in DataVO response");
              ignored.printStackTrace();
              Here's the code in the JSP sending the response back to the applet. The 'dvo'
              object is the object which is serialized and has gets and sets for the diff. data
              elements. When I print the 'dvo' before writing the object to outputStream it
              prints the correct values for the data element.
              // send response
              response.setStatus(HttpServletResponse.SC_OK);
              ObjectOutputStream outputStream = new ObjectOutputStream (new BufferedOutputStream
              (response.getOutputStream()));
              outputStream.writeObject(dvo);
              outputStream.flush();
              ERROR is as follows:
              Error in DataVO response
              java.io.StreamCorruptedException: InputStream does not contain a serialized object
              at java/io/ObjectInputStream.readStreamHeader
              at java/io/ObjectInputStream.<init>
              What am I doing wrong?. Please respond soon. The applet is run on IIS and the
              JSP in on weblogic 6.1. I'm not sure if that makes any difference.
              

  • [java.nio] StreamCorruptedException when deserializing objects

    Hello everybody!
    I made a messaging (chat) program using java.io where all the client-server communication is done by serializing small objects. Now I would like to covert the server side to the NIO concept and I'm already struck. I successfully pass objects to the client and the client deserializes them, but only the first one! When it try to read the second it fails with a StreamCorruptedException.
    Here�s a sample (testing) code. In the server run() method I first serialize a string, then get its byte array from ByteArrayOutputStream and in the loop periodically send this byte array through the channel. On the client side I just read the deserialized object.
    Server run():
    public void run() {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject("abcdefgh");
                byte[] objectArr = baos.toByteArray();
                baos.close();
                oos.close();
                ByteBuffer buff = ByteBuffer.allocate(objectArr.length);
                buff.put(objectArr);
                buff.flip();
                while(true) {
                    selector.select();
                    Set keys = selector.selectedKeys();
                    for (Object o : keys) {
                        SelectionKey key = (SelectionKey)o;
                        if (key.isAcceptable()) {
                            ServerSocketChannel server = (ServerSocketChannel) key.channel();
                            clientChannel = server.accept();
                            if (clientChannel == null)
                                continue;
                            clientChannel.configureBlocking(false);
                            SelectionKey clientKey = clientChannel.register(selector, SelectionKey.OP_WRITE);
                        } else if (key.isWritable()) {
                            SocketChannel client = (SocketChannel) key.channel();
                            if (buff.hasRemaining()) {
                                client.write(buff);
                            } else {
                                buff.clear();
                                buff.put(objectArr);
                                buff.flip();
                    try {
                        Thread.currentThread().sleep(2000);
                    } catch (InterruptedException e) {
                        return;
            } catch (IOException e) {
                e.printStackTrace();
        }Client run():
    public void run() {
            try {
                soc = new Socket("localhost", 4000);
                ObjectInputStream ois = new ObjectInputStream(soc.getInputStream());
                while(true) {
                    Object d = ois.readObject();
                    System.out.println("data = " + d.toString());
            } catch (Exception ex) {
                ex.printStackTrace();
        }At the second read I get a StreamCorruptedException.
    Apart from this I would like some hints in how to implement the application with NIO. For example how can I tell the objects apart on the client side � should I send every time a byte array before the object, which tells the length of the next coming object? This is probably not a 100% bulletproof solution and presents additional data transfer?
    Than you in advance!

    OK, I found a solution but I don't like it, because I don't understand it.
    The ObjectOutputStream adds a header (4 bytes) to the stream - if I send the array with those four bytes I get an StreamCorruptedException. If I send the array without the header I also get a StreamCorruptedException: "invalid stream header".
    If I reconstruct the object, by calling ObjectOutputStream.writeObject() and get it's byte array from ByteArrayOutputStream.toByteArray(), every time I have to fill the ByteBuffer, then it works.
    Here's the modified sending block, for the above example:
    } else if (key.isWritable()) {
                            SocketChannel client = (SocketChannel) key.channel();
                            if (buff.hasRemaining()) {
                                client.write(buff);
                            } else {
                                //* ---- added code ---------
                                baos.reset();
                                oos.writeObject("abcdefgh");
                                objectArr = baos.toByteArray();
                                buff.clear();
                                buff.put(objectArr);
                                buff.flip();
                        }   I really don't understand why I have to write the object in the object stream every time. I used ObjectOS and ByteArrayOS, to get the object byte array and then I thought I could forget about those streams and use this array to fill the ByteBuffer. What changes if I send the object through this process with every iteration (and how this harms speed - it's like sending everything twice)? If someone would explain this to me I would appreciate it much.

  • StreamCorruptedException from Stateless Session bean to java class

    Hi all,
    We have 2 servers, a ColdFusion App server which contains suns jdk 1.4.2 and websphere appserver using Ibm jdk, 1.4.2. On Server 1, we have a standalone java class which does a stateless session bean lookup and requests a service from it. On server 2(websphere), we have a stateless session bean deployed which connects to a database using a jndi lookup, executes a query and returns back a CachedRowSet object (which populates the ResultSet from the above query.) In some cases, session bean returns back an array of objects or String objects or just plain int values.
    When the java class on server 1 invokes the methods returning CachedRowSet, we are getting a StreamCorruptedException, whereas on the server side, there is no exception. everything gets executed fine on websphere. This is the case only for CachedRowSet and not for other return types(as mentioned earlier the session bean returns an array of object in some cases which the java class on server 1 is successfully able to use).
    This is what the piece of code look like on server 1:
    // First gets a StatelessSessionBean using suns InitialContextFactory
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL,"iiop://localhost:2809");
    System.out.println("Creating initial context");
    Context ctx = new InitialContext(env);
    System.out.println("Initial context created.");
    Object homeObj = ctx.lookup("cell/nodes/localhost/servers/server1/ejb/SSBHome");
    SSBHome eHome = (SSBHome)PortableRemoteObject.narrow(homeObj,SSBHome.class);
    System.out.println("Got Home");
    SSB eBean = eHome.create();
    CachedRowSet crs = eBean.getAccts(param1, param2);
    //This is the line of code which throws the exception.
    The stacktrace shoows as follows:
    Got Home
    java.io.StreamCorruptedException
         at com.sun.corba.se.internal.io.IIOPInputStream.inputRemoteMembersForReadFields(IIOPInputStream.java:1675)
         at com.sun.corba.se.internal.io.IIOPInputStream.readFields(IIOPInputStream.java:1595)
         at com.sun.corba.se.internal.io.InputStreamHook.readFields(InputStreamHook.java:177)
         at java.math.BigInteger.readObject(BigInteger.java:3034)
         at com.sun.corba.se.internal.io.IIOPInputStream.readObject(Native Method)
         at com.sun.corba.se.internal.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1298)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObject(IIOPInputStream.java:908)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:261)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectField(IIOPInputStream.java:1484)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputClassFields(IIOPInputStream.java:1893)
         at com.sun.corba.se.internal.io.IIOPInputStream.defaultReadObjectDelegate(IIOPInputStream.java:424)
         at com.sun.corba.se.internal.io.InputStreamHook.defaultReadObject(InputStreamHook.java:163)
         at java.math.BigDecimal.readObject(BigDecimal.java:1084)
         at com.sun.corba.se.internal.io.IIOPInputStream.readObject(Native Method)
         at com.sun.corba.se.internal.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1298)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectUsingFVD(IIOPInputStream.java:1182)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:259)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:948)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:289)
         at com.sun.corba.se.internal.corba.TCUtility.unmarshalIn(TCUtility.java:266)
         at com.sun.corba.se.internal.corba.AnyImpl.read_value(AnyImpl.java:561)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_any(CDRInputStream_1_0.java:635)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_any(CDRInputStream.java:260)
         at com.sun.corba.se.internal.javax.rmi.CORBA.Util.readAny(Util.java:100)
         at javax.rmi.CORBA.Util.readAny(Util.java:90)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.read_Array(ValueHandlerImpl.java:586)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:244)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectField(IIOPInputStream.java:1577)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputClassFields(IIOPInputStream.java:1796)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObject(IIOPInputStream.java:913)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:261)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:948)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:289)
         at com.sun.corba.se.internal.corba.TCUtility.unmarshalIn(TCUtility.java:266)
         at com.sun.corba.se.internal.corba.AnyImpl.read_value(AnyImpl.java:561)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_any(CDRInputStream_1_0.java:635)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_any(CDRInputStream.java:260)
         at com.sun.corba.se.internal.javax.rmi.CORBA.Util.readAny(Util.java:100)
         at javax.rmi.CORBA.Util.readAny(Util.java:90)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.read_Array(ValueHandlerImpl.java:586)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:244)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectField(IIOPInputStream.java:1577)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputClassFields(IIOPInputStream.java:1796)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObject(IIOPInputStream.java:913)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:261)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectField(IIOPInputStream.java:1577)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputClassFields(IIOPInputStream.java:1796)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObject(IIOPInputStream.java:913)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:261)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.EJBProj._SSB_Stub.getAccts(_SSB_Stub.java:240)
         at com.test.Test1.getAccts(Test1.java:101)
         at com.test.Test1.<init>(Test1.java:65)
         at com.test.Test1.main(Test1.java:81)
    java.io.IOException: Unable to read value from underlying bridge : Serializable readObject method failed internally
         at com.sun.corba.se.internal.io.IIOPInputStream.throwExceptionType(Native Method)
         at com.sun.corba.se.internal.io.IIOPInputStream.defaultReadObjectDelegate(IIOPInputStream.java:446)
         at com.sun.corba.se.internal.io.InputStreamHook.defaultReadObject(InputStreamHook.java:163)
         at java.math.BigDecimal.readObject(BigDecimal.java:1084)
         at com.sun.corba.se.internal.io.IIOPInputStream.readObject(Native Method)
         at com.sun.corba.se.internal.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1298)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectUsingFVD(IIOPInputStream.java:1182)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:259)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:948)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:289)
         at com.sun.corba.se.internal.corba.TCUtility.unmarshalIn(TCUtility.java:266)
         at com.sun.corba.se.internal.corba.AnyImpl.read_value(AnyImpl.java:561)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_any(CDRInputStream_1_0.java:635)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_any(CDRInputStream.java:260)
         at com.sun.corba.se.internal.javax.rmi.CORBA.Util.readAny(Util.java:100)
         at javax.rmi.CORBA.Util.readAny(Util.java:90)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.read_Array(ValueHandlerImpl.java:586)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:244)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectField(IIOPInputStream.java:1577)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputClassFields(IIOPInputStream.java:1796)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObject(IIOPInputStream.java:913)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:261)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:948)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:289)
         at com.sun.corba.se.internal.corba.TCUtility.unmarshalIn(TCUtility.java:266)
         at com.sun.corba.se.internal.corba.AnyImpl.read_value(AnyImpl.java:561)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_any(CDRInputStream_1_0.java:635)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_any(CDRInputStream.java:260)
         at com.sun.corba.se.internal.javax.rmi.CORBA.Util.readAny(Util.java:100)
         at javax.rmi.CORBA.Util.readAny(Util.java:90)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.read_Array(ValueHandlerImpl.java:586)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:244)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectField(IIOPInputStream.java:1577)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputClassFields(IIOPInputStream.java:1796)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObject(IIOPInputStream.java:913)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:261)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObjectField(IIOPInputStream.java:1577)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputClassFields(IIOPInputStream.java:1796)
         at com.sun.corba.se.internal.io.IIOPInputStream.inputObject(IIOPInputStream.java:913)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:261)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:247)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:209)
         at com.sun.corba.se.internal.iiop.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1084)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:293)
         at com.EJBProj._SSB_Stub.getAccts(_SSB_Stub.java:240)
         at com.test.Test1.getAccts(Test1.java:101)
         at com.test.Test1.<init>(Test1.java:65)
         at com.test.Test1.main(Test1.java:81)
    Again, everything seems to work fine on websphere server.
    Any Clue of why this is happening?
    All suggestions are greatly appreciated.
    Thanks
    Neorav
    Message was edited by:
    NeoravB

    Sorry for the confusion!
    The solution mentioned above is not the right solution.
    The above given code works fine irrespective of having corbaloc in the url, if you are working in the IBMs jvm.
    It fails if you are working in suns jvm.
    Anyone with any idea whats missing here.
    Thanks a lot for any suggestion/ideas
    Neorav

  • UTFDataFormatException and StreamCorruptedException

    We have an applet client that is communicating with a servlet in Apache Tomcat through HttpUrlConnection
    using ObjectOutputStream / ObjectInputStream.
    Everything has been working fine, but recently one of our users has had some serious problems
    with the client-server communication. Basically this occurs so that client will throw
    UTFDataFormatExceptions and StreamCorruptedExceptions to Java console. These exceptions are
    thrown pretty randomly, for example sometimes 10 times in a row (out of 10 tries) and then
    a few times with no errors and after that more exceptions and so on.
    These exceptions are thrown when client is loading quite a big chunk of data from server.
    According to server access-logs something between 1500000 and 2000000 bytes are transferred.
    Server side logs show no errors.
    JDK on server is 1.4.2_xx and client side Java plug-in is 1.5.0_xx. We have tried different
    Java plug-in versions with no change.
    Other users get those exceptions too when using this particular environment, but less frequently.
    I've tried to debug the applet and the funny thing is, that when I'm running the applet through
    my IDE (JBuilder) I get no exceptions.

    ejp wrote:
    What you're doing with all the extra buffering is pointless and error-prone. Get rid of the ByteArrayOutputStream and ByteArrayInputStream and connect the ObjectInputStream and ObjectOutputStream directly to the socket.Actually the reason for the extra buffering is due to the use of nio channels. I was basically following the advice from http://forum.java.sun.com/thread.jspa?threadID=449283&messageID=2040791 , i.e.,
    dmbdmb wrote:
    You could always call layer an ObjectOutputStream ontop of a ByteArrayOutputStream, write the objects, then grab the bytes from the ByteArrayOutputStream and write them with niobut unfortunately I still got the above exceptions using the scheme described. Are there other reliable ways to accomplish the same task?

  • Problems moving from 1.3.1 to 1.4 (StreamCorruptedException)

    Hi all,
    I'm having a terrible time moving my existing project from 1.3 to 1.4. The GUI (running on W2k) works fine, but the server side of the app (running on Solaris 2.6 w/ current patches & Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)) is giving me fits in a couple of places. The app has been in production for over a year using 1.3.1.
    Everything has gone smoothly with the exception of a couple of problems that I just can't seem to get around. Namely, I get UnmarshalExceptions with nested StreamCorruptedExceptions on some of the RMI calls. Everything I send across the wire implements Serializable.
    I got around the first one - Sending an array of objects that each had as a member variable a java.text.MessageFormat object blew up with the before mentioned exception. Wierd thing is, if I send just one of those objects it's not a problem, only when sending an array of them is it bad. Changing the type to String and then creating MessageFormat objects from those strings lazily on the client got around the problem. (yuck)
    Anyways, I now have two more issues similar to the above mentioned that I can't seem to find a work-around for. These objects only contain data members of primitive and/or String type. They also implement Serializable, so I can't understand what the problem is. Below is a copy of the exception I'm getting.
    |java.rmi.ServerException: RemoteException occurred in server
    thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.io.StreamCorruptedExceptionjava.rmi.ServerException: RemoteException occurred in server thread; nested excepti
    on is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.io.StreamCorruptedException
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
    at sun.rmi.transport.Transport$1.run(Transport.java:148)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:536)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
    at com.<myco>.<myprod>.interfaces.<host>.Service_Stub.getResponse(Unknown Source)
    at com.<myco>.<myprod>.interfaces.<host>.Factory.getResponse(Factory.java:182)
    at com.<myco>.<myprod>.maintenance.hosts.MaintenanceHost.getWorkload(MaintenanceHost.java:812)
    at com.<myco>.<myprod>.maintenance.MaintenanceService.getWorkload(MaintenanceService.java:2359)
    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:324)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
    at sun.rmi.transport.Transport$1.run(Transport.java:148)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:536)
    Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.io.StreamCorruptedException
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:249)
    ... 6 more
    Caused by: java.io.StreamCorruptedException
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1291)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1830)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1756)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1636)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1264)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1830)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1756)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1636)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1264)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:322)
    at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:297)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:246)
    ... 6 more
    I've utilized 1.4's ability to getCause(), get the StackTraceElement[] of it, and iterate to see what is present in the "...6 more". If anyone needs to see that to help me, I'll gladly post it as well.
    Thanks in advance for any assistance, I've spent way too much time working on this issue.
    Eric

    I found this thread while searching for an answer to my question and I am wondering if there is any update. Here is my situation...
    We have a 100% Java application which utilizes RMI only. It has been running in production on the 1.2.2 JDK for over four years in many operating environments (Solaris 8, 9, Windows 9x, 2K and XP, Linux).
    We have finally decided to bite the bullet and upgrade the app to 1.4.2 (specifically the _04 release).
    We are getting the StreamCorruptedException consistently. After narrowing the problem we have uncovered that the issue is, indeed, directly related to java.text.Format decendants (in this case SimpleDateFormat and DecimalFormat.
    We have a class (call it OurClass)which includes a SimpleDateFormat instance. SimpleDateFormat implements Serializable (as does OurClass). When an object of OurClass is enstantiated an instance of SimpleDateFormat is created. When this class is passed as a parameter to a server call and needs to be serialized the StreamCorruptedException is thrown. If we comment out the "new SimpleDateFormat()" the code completes successfully.
    The same is true for DecimalFormat.
    What gives? This thread started in late '02 and was last addressed here in early '03. I see that someone posted that some problems can be expected in RMI over IIOP but we have a Java-to-Java RMI-only application.

  • Reg. StreamCorruptedException

    Hi,
    Can U help me How 2 solve "StreamCorruptedException" problem.
    This exception i'm getting when i'm trying 2 use readObject().
    First time it is giving EOFException().from next time onwards it is giving StreamCorruptedException().
    code is:
    import java.io.*;
    public class FileTry1
    // instance variables - replace the example below with your own
    private UserRec currUser;
    * Constructor for objects of class FileTry1
    public FileTry1()
    // initialise instance variables
    UserRec u1 = new UserRec(0, "John3", 1000);
    UserRec u2 = new UserRec(1, "joe3", 2000);
    UserRec u3 = new UserRec(100, "naren", 2000);
    try {
    FileOutputStream ostream = new FileOutputStream("t.tmp", true);
    ObjectOutputStream p = new ObjectOutputStream(ostream);
    p.writeObject(u1);
    p.writeObject(u2);
    p.writeObject(u3);
    p.flush();
    ostream.close();
    p.close();
    catch (Exception e) {
    System.out.println(e);
    } // end catch
    ReadIt ri = new ReadIt();
    public static void main(String args[] ) {
    new FileTry1();
    System.exit(0);
    } // end class FileTry1
    import java.io.*;
    public class UserRec implements Serializable
    // instance variables - replace the example below with your own
    public int userID;
    public String userName;
    public int salary;
    * Constructor for objects of class UserRec
    public UserRec()
    // initialise instance variables
    userID = 0;
    userName = "";
    salary = 0;
    public UserRec(int id, String name, int sal) { 
    // overridden constructor w/ values
    userID = id;
    userName = name;
    salary = sal;
    } // end constructor...
    import java.io.*;
    public class ReadIt
    // instance variables - replace the example below with your own
    private UserRec urec;
    * Constructor for objects of class ReadIt
    public ReadIt()
    // initialise instance variables
    urec = new UserRec();
    FileInputStream istream = null;
    ObjectInputStream p = null;
    // now try to read the file we just wrote
    try {
    istream = new FileInputStream("t.tmp");
    p = new ObjectInputStream(istream);
    System.out.println("Now going to try to read the file back in");
    boolean EOF = false;
    int count=0;
    while ( !EOF ) {
    try {
    UserRec t_urec = (UserRec) p.readObject();
    System.out.println("rec No.: " + t_urec.userID + " Name: " + t_urec.userName);
    if(++count == 4) break;
    } // end try
    catch (Exception f) {
    EOF = true;
    System.out.println("in ReadIt at EOF catch: " + f);
    f.printStackTrace();
    } // end catch EOF
    } // end while ( !EOF )
    istream.close();
    p.close();
    } // end try
    catch (Exception ee) {
    System.out.println("Overall ReadIt catch: " +ee);
    } // end ReadIt()
    } // end class ReadIt
    Thanks in advance
    Naren.

    in ReadIt class you make 4 as 3 For your convinenece i am pasting all the files back compiled and runned,
    import java.io.*;
    public class FileTry1
    // instance variables - replace the example below with your own
    private UserRec currUser;
    * Constructor for objects of class FileTry1
    public FileTry1()
    // initialise instance variables
    UserRec u1 = new UserRec(0, "John3", 1000);
    UserRec u2 = new UserRec(1, "joe3", 2000);
    UserRec u3 = new UserRec(100, "naren", 2000);
    try {
    FileOutputStream ostream = new FileOutputStream("t.tmp", true);
    ObjectOutputStream p = new ObjectOutputStream(ostream);
    p.writeObject(u1);
    p.writeObject(u2);
    p.writeObject(u3);
    p.flush();
    p.close();
    ostream.close();
    catch (Exception e) {
    System.out.println(e);
    } // end catch
    ReadIt ri = new ReadIt();
    public static void main(String args[] ) {
    new FileTry1();
    System.exit(0);
    } // end class FileTry1
    import java.io.*;
    public class ReadIt
    // instance variables - replace the example below with your own
    private UserRec urec;
    * Constructor for objects of class ReadIt
    public ReadIt()
    // initialise instance variables
    urec = new UserRec();
    FileInputStream istream = null;
    ObjectInputStream p = null;
    // now try to read the file we just wrote
    try {
    istream = new FileInputStream("t.tmp");
    p = new ObjectInputStream(istream);
    System.out.println("Now going to try to read the file back in");
    boolean EOF = false;
    int count=0;
    while ( !EOF ) {
    try {
    UserRec t_urec = (UserRec) p.readObject();
    System.out.println("rec No.: " + t_urec.userID + " Name: " + t_urec.userName);
    if(++count == 3) break;
    } // end try
    catch (Exception f) {
    EOF = true;
    System.out.println("in ReadIt at EOF catch: " + f);
    f.printStackTrace();
    } // end catch EOF
    } // end while ( !EOF )
    istream.close();
    p.close();
    } // end try
    catch (Exception ee) {
    System.out.println("Overall ReadIt catch: " +ee);
    } // end ReadIt()
    } // end class ReadIt
    import java.io.*;
    public class UserRec implements Serializable
    // instance variables - replace the example below with your own
    public int userID;
    public String userName;
    public int salary;
    * Constructor for objects of class UserRec
    public UserRec()
    // initialise instance variables
    userID = 0;
    userName = "";
    salary = 0;
    public UserRec(int id, String name, int sal) {
    // overridden constructor w/ values
    userID = id;
    userName = name;
    salary = sal;
    } // end constructor...
    }All The Best

  • Saving and loading serialized objects (StreamCorruptedException)

    Hello,
    I am relatively new to Serialization (coming to that, a bit new to Java too) and I am having a problem with the following:
    I am saving a number of serialized objects (all of the same class) in a file using the following way (the method is called multiple times to save a list of TeamMember objects):
    Note: TeamMember is a custom class.
    public void addTeamMember(TeamMember p) {
                outputStream = new ObjectOutputStream( new FileOutputStream( "team.dat", true ) );
                outputStream.writeObject( p );
                outputStream.flush();
                outputStream.close();
                outputStream = null;
    }Then I'm trying to retrieve the objects from the file and display them. The method used is the following (it will loop through the file until found or it throws an EOFException. Is using the EOFException good practice to search through the entire file?):
    public TeamMember getTeamMember(String id) {
            TeamMember currentMember = null;
            try {
                boolean found = false;           
                inputStream = new ObjectInputStream( new FileInputStream( "team.dat" ) );
                while ( !found ) {
                    currentMember = (TeamMember)inputStream.readObject();
                    if ( currentMember.getId().equals( id ) )
                        found = true;
                } // end while
                closeInputFile();
                return currentMember;
            } // end try
            catch ( EOFException e ) { // end of file reached
                closeInputFile();           
                return null;
            } // end catch
            catch ( IOException e ) {
                closeInputFile();
                System.err.println( e.getMessage() );
                return null;
            } // end catch
        }Now as a test, I am adding 3 members with IDs 1, 2 and 3 respectively. Then I am calling getTeamMember three times with the different IDs. With ID "1", it works fine. When I give it ID 2, it gives an IOException with message "StreamCorruptedException: invalid type code: AC".
    While tracing the program, I've seen that it always gives me that error when reading past the first object saved in the file.
    Am I saving the objects in a wrong way, or reading them is done incorrectly?
    Any help is much appreciated.
    I hope I was clear enough, and that I posted in the correct forum.
    Thanks in advance.
    Andrew.

    If that is so, might you hint me for a work around?
    I want to append objects in a single file, then be able to find and read an object from the file.
    Thanks again.
    Andrew

  • StreamCorruptedException - what is causing it?

    I am developing a networked multiplayer game in Java, but I am having problems when it comes to sending data around the network. The game will run fine for a seemingly random amount of time (usually between about 10 seconds and 2 minutes) before a StreamCorruptedException occurs in each of the clients. 90% of the time the message says "invalid type code: 00" but sometimes I get "invalid handle value" or various others.
    I have searched for ages for more information on this, but there isn't much help available. I have tried a couple of things suggested in other threads, to no avail.
    The code that listens for connections from clients:
    while(numConnections < MAX_CONNECTIONS) {
        socket = serverSocket.accept();
        numConnections++;
        System.out.println("Connection from " +socket.getInetAddress());
        ServerThread thread = new ServerThread(socket);+
        thread.start();
    }The ServerThread class handles each connection and contains the following method which is used to send objects to all connected clients:+
    public static void sendToClients(Object o) {
        try {
            for(int i = 0; i < connections.size(); i++) {
                ServerThread thread = connections.elementAt(i);
                thread.out.writeObject(o);
                thread.out.flush();
    catch(IOException e) {
        e.printStackTrace();
    }The Client class reads the objects sent by the server:
    try {
                Object o;
                while(true) {
                    o = inputStream.readObject();
    }The exception occurs in the o = inputStream.readObject() line
    Sorry about the bad formatting... first post and for some reason the input box jumps all over the place when I'm typing so I can't see what's being written!
    Edited by: interdreamuk on Feb 23, 2010 9:48 AM

    No, I haven't seen AC yet... only one input and output stream is created per socket and used for the life of that socket. The most common code I get is 00, but I have also seen 23 and 79. I tried searching for a list of what the codes mean, but can't find much info about the causes of this exception at all really. I know it gets thrown when "Control information in the stream is inconsistent" according to the API, but that doesn't really help much.
    Also, after reading about this for hours, I changed writeObject to writeUnshared (just a shot in the dark really), which for some reason seems to have significantly increased the amount of time for which the application will run before the exception occurs.
    Edited by: interdreamuk on Feb 24, 2010 12:46 AM

  • StreamCorruptedException while using JWS

    Hello,
    I'm wanting to deploy the client of a client/server networked app in JWS, but for some reason I'm getting StreamCorruptedExceptions when I try to deserialize Objects contained in network messages. This doesn't happen when I run the app outside of JWS, so it appears to be some weird interaction with JMS. Here are all the details I can think of:
    The app is being distributed as one jar, including all libraries, by using the Fatjar plugin for Eclipse.
    I'm using Apache Tomcat v5.5.12 as the application server so that I can click a link in a browser to start the JWS app.
    I'm using ActiveMQ v4.0M3 as a JMS provider to handle passing messages across the network. (The same thing happens with ActiveMQ v3.2.1)
    This is the error print out:
    Caught: javax.jms.JMSException: Failed to build body from bytes. Reason: java.io.StreamCorruptedException
    javax.jms.JMSException: Failed to build body from bytes. Reason: java.io.StreamCorruptedException
         at org.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:34)
         at org.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:173)
         at com.shai.ogma.networking.JMSLink.onMessage(JMSLink.java:115)
         at org.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:703)
         at org.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:95)
         at org.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:148)
         at org.activemq.thread.SimpleTaskRunner.runTask(SimpleTaskRunner.java:129)
         at org.activemq.thread.SimpleTaskRunner.access$100(SimpleTaskRunner.java:44)
         at org.activemq.thread.SimpleTaskRunner$1.run(SimpleTaskRunner.java:62)
         at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:643)
         at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:668)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.StreamCorruptedException
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.readObject(Unknown Source)
         at java.util.HashMap.readObject(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
         at java.io.ObjectInputStream.readSerialData(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.readObject(Unknown Source)
         at java.util.HashMap.readObject(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
         at java.io.ObjectInputStream.readSerialData(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
         at java.io.ObjectInputStream.readSerialData(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.readObject(Unknown Source)
         at java.util.HashMap.readObject(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
         at java.io.ObjectInputStream.readSerialData(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.readObject(Unknown Source)
         at com.shai.ogma.messaging.OgmaMessage.readExternal(OgmaMessage.java:245)
         at java.io.ObjectInputStream.readExternalData(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Unknown Source)
         at java.io.ObjectInputStream.readObject(Unknown Source)
         at org.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:167)
         ... 10 more
    Notes about the error message:
    The thing it is getting stuck on while trying to deserialize is one of my own classes with readObject() and writeObject() defined.
    It can serialize/deserialize without problems outside of JWS.
    All the classes I'm serializing are in synch between the server and the client. I.e. there shouldn't be any problems with serialversionUID caused by code being at different versions.
    The code at org.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:167) doesn't appear to be doing anything funny.
    Does anyone have any clues what might be causing this behavior and how to fix it?
    Thanks!

    Here is my guess. The browser VM has some subtle interractions with the browser. An SSL connection usually starts with the server sending a certificate and the client 'accepting it'. The acceptance or rejection is based on the root certificates configured in the client. The browser has such a 'database' of root certificates. I bet the browser VM is using the same database as the browser.
    When you run the application stand-alone, the database is somewhere in the JRE. Somehow the root certificate of your server certificate is not there.

  • StreamCorruptedException

    Hi,
    I'm trying to send serialized objects over socket connection, see the code snippet below.
    import java.io.*;
    import java.net.*;
    public class Test2 {
    private ObjectOutputStream oos;
    private ObjectInputStream ois;
    private Socket s;
    public Test2(String host, int port) {
         try {
         s = new Socket(host, port);
         s.setTcpNoDelay(true);
         oos = new ObjectOutputStream(s.getOutputStream());
         ois = new ObjectInputStream(s.getInputStream());
         oos.writeObject("data");
         oos.flush();
         System.out.println(ois.readObject());
         } catch (UnknownHostException e) {
         e.printStackTrace();
         } catch (IOException ioe) {
         ioe.printStackTrace();
         } catch (ClassNotFoundException cnfe) {
         cnfe.printStackTrace();
    public static void main(String args[]) {
         Test2 t = new Test2("localhost", 5000);
    When I compiled the program, I got the following error message,
    java.io.StreamCorruptedException: invalid stream header
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at Test2.<init>(Test2.java:17)
    at Test2.main(Test2.java:63)
    Can someone give pointers on how to solve this problem?
    Thank you in advance for your help!

    If the other end isn't written in Java using ObjectInput/OutputStreams you can't use Serialization in either direction.

  • StreamCorruptedException in ObjectInputStream

    Hello!! I have a problem with serialization and ObjectInputStream/ObjectOutputStream classes:
    I have two programs. The first program writes objects in a file. Here is the code:
    FileOutputStream f = new FileOutputStream ("filename", true);
    ObjectOutputStream o = new ObjectOutputStream (f);
    o.writeObject (objetTest);
    f.close();
    o.close();
    The other program reads these objects:
    FileInputStream f = new FileInputStream ("filename");
    ObjectInputStream o = new ObjectInputStream (f);
    TestClass objetTest = (TestClass)o.readObject();
    f.close();
    o.close();
    The first program is executed and when it finishes the second program is executed. Imagine that the first program writes two object and the second program wants to read these two objects. The second program reading the first object runs ok, but when try to read the second object a java.io.StreamCorruptedException appears
    Anybody can help me? Any ideas?
    Cheers
    Kike

    A newly created ObjectOutputStream first writes a header to its encapsulated
    OutputStream. From your code I see that you're using the FileOutputStream
    in 'append mode'. So, if you write two objects, running the above code twice,
    you basically get this in your file: <header><object><header><object>.
    You're just using one ObjectInputStream; when it gets created it reads the
    header and then attempts to read objects from the encapsulated InputStream.
    It encounters another header when it attempts to read a second object,
    hence the StreamCorruptedException.
    kind regards,
    Jos

  • Streamcorruptedexception deserializing in method getClassDesc

    I�m serializing a class, sending from a servlet to an applet, and when I deserialize the class inside the browser I get a StreamCorruptedException, in the method getClassDesc. But when I run (or debug) the applet inside my IDE (NetBeans) the deserializing process works OK. I'm thinking in a classpath problem, but I have revised the classes used in the serialized class and I put all of them in the applet jar file.
    The process only fails with a concrete class deserialization, I know the process is OK because can send another objects without problem, same in the browser than in the IDE. The problem is with the object with more size, I don't know about limits, but I download the entire object in a byte array before, then I decompress and deserialize.
    Any clues?

    Hi, try clear your stream before writing any objects to it.
    (ObjectOutputStream.flush())
    This is nessary to avoid that Headerinformatons will be
    joined with the object, which appears to be corrupt for the
    ObjectInputStream if this happens.
    Hope this helps.
    Greetings Michael

  • Getting "java.io.StreamCorruptedException: invalid stream header"

    When creating a self made Stream (MacInputStream) and then using an ObjectInputStream over it to read Objects from a socket, I get this error:
    java.io.StreamCorruptedException: invalid stream header
         at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:764)
         at java.io.ObjectInputStream.<init>(ObjectInputStream.java:277)
         at TServidor.run(TServidor.java:32)
    Is there any special feature that the "self-made" streams have to implement to be possible to use ObjectInput streams over them :P ?
    Here is the MacInputStream.java code:
    import java.io.Closeable;
    import java.io.FilterInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Arrays;
    import javax.crypto.Mac;
    public class MacInputStream extends FilterInputStream implements Closeable{
         private Mac mac; // algorithm
         private byte [] mmac; //message MAC
         private boolean FIRST_TIME;
         public MacInputStream(InputStream is,Mac mac) {
              super(is);
              this.mac=mac;
              FIRST_TIME=true;
    public int read() throws IOException{
              if(FIRST_TIME){
                   mmac = new byte [mac.getMacLength()];
                   super.read(mmac);
              if(super.in.available()==0){
                   FIRST_TIME=true;
                   return -1;
              int rbyte = super.in.read();
              FIRST_TIME=false;
              mac.update((byte)rbyte);
              System.out.println("available: "+super.in.available());          
              if(super.in.available()==0){
                   byte [] macres =mac.doFinal();
                   System.out.println("message MAC: "+new String(mmac));
                   System.out.println("calculated MAC: "+new String(macres));
                   if(!Arrays.equals(macres, mmac)){
                        throw new IOException("violated integrity");
              return rbyte;
    public int read(byte [] b) throws IOException{
         if(FIRST_TIME){
              mmac = new byte [mac.getMacLength()];
              super.in.read(mmac);          
         if(super.available()==0){
              FIRST_TIME=true;
              return -1;
         int rbytes = super.in.read(b);
         FIRST_TIME=false;
         mac.update(b);
         if(super.available()==0){
              byte [] macres =mac.doFinal();
              if(!Arrays.equals(macres, mmac)){
                   throw new IOException("violated integrity");
         return rbytes;
    }And here is the "main" function where the exception gets thrown:
    public void run() {
         try {
              ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
              Mac mac = Mac.getInstance("HmacMD5");
              Key key = KeyGenerator.getInstance("HmacMD5").generateKey();          
              oos.writeObject(key);
              oos.flush();
              mac.init(key);          
              ObjectInputStream cis = new ObjectInputStream(new MacInputStream(s.getInputStream(),mac));
             String test;
             try {
                   while (true) {
                        test = (String)cis.readObject();
                        System.out.println(ct + " : " + test);
              } catch (EOFException e) {
                   System.out.println("["+ct + "]");
              } finally {
              if (cis!=null) cis.close();
              if (oos!=null) oos.close();
         } catch (Exception e) {
             e.printStackTrace();
        }It's exactly in the line: ObjectInputStream cis = new ObjectInputStream(new MacInputStream(s.getInputStream(),mac));Any ideas?
    I'm starting to desperate :P

    (a) I still don't see where you are writing the MAC that you're reading. You're reading something, but it's all or part of the Object stream header I described above, which is why ObjectInputStream' constructor is throwing that exception.
    (b) You don't need to override read(byte[] b) when you extend FilterInputStream, but you do need to override read(byte[] b, int offset, int length), and you need to do it like this:
    public int read(byte[] buffer, int offset, int length) throws IOException
      int count = 0;
      do
        int c = read();
        if (c < 0)
            break;
        buffer[offset+count++] = (byte)c;
      } while (count < length && available() > 0);
      return count > 0 ? count : -1;
    }This way the read() method gets to see every byte that's read and to do its MAC thing or whatever it does. The above is one of only two correct uses of available() in existence: it ensures that you only block once while reading, which is the correct behaviour e.g. on a network.

  • Java.io.StreamCorruptedException

    Hi I'm currently working on a project which deals with objectStreams.
    When a client connects to the server, the server creates a send thread and a receive thread to serve the client.As one can imagine there is an ObjectInputStream accepting objects from the client in the receive thread and an ObjectOutputStream in the send thread to send objects.
    However in order to assure that the client has not disconnected there is one more ObjectOutputStream in the receive thread that send PING messages to the client. The addition of this stream causes StreamCorruptedException. When rewriting the code using DataStreams ,instead of ObjectStreams,it works perfectly.
    I make sure that every ObjectOutputStream is flushed,i create them before the corresponding ObjectInputStreams and i access the sockets using synchronized (socket)when i attempt to get the input and ouput streams.
    When I disable the ping function thus, not creating the ObjectOutputStream from the receive thread side, my application is working...
    can anybody give me a tip?
    It would be very much appreciated. Thanks in advance

    can anybody give me a tip?Yes. Don't. Use the same ObjectOutputStream for both purposes, or use the DataOutputStream for the ping as you already discovered. Object streams have headers and state so you can't just add another one to the same stream.

Maybe you are looking for

  • Problem with Photoshop Elements Printing

    I have been using Photoshop Elements for a couple of years now and know it pretty well.  Today while attempting to print, a strange problem came up:  After going through the protocol to make a print, just before the image prints PE does a very fast a

  • Illustrator, PC to Mac, degree symbols

    Here is an odd issue. I am receiving files in Illustrator CS3 EPS format. They are being created on Windows PCs. Some of the files have art with degree symbols showing the angles or polygons. The file is then placed in Quark Xpress 6.52. If the EPS f

  • Website works in Firefox, but does not load in IE, Safari, Chrome.

    site: www.lightspinnersweb.com Page is a html wrapper around a  .swf.    The Flash includes .xml pages.  Shows no errors and works fine in Dreamweaver when 'test page in IE'. The Wc3 only shows errors in the <noscript....embed... section. Have tried

  • How to download english version iBooks Author from the Belgian store?

    I have downloaded Ibooks Author from the Belgian store and after looking up on prefferences I see that there are no language options.  The version I downloaded seemed to have only French language funcionalities.  I appreciate it if someone can help m

  • Videos missing from iPhoto after prompted to clear from memory card

    I just imported a couple of videos from my GoPro camera into iPhoto. After the videos were imported, I created an album. Once the videos finished importing I was prompted on screen to erase the video's from the memory card and that the import was com