1

I have a EJB client and a EJB2 server which runs on a JBoss 4 server. It was working fine for same JVM version(1.6). Then I upgrade client JVM to 1.7(but compiler version is 1.6) while keeping server JVM as the same(1.6). java.io.StreamCorruptedException: unexpected end of block data error occurs in client side if server method returns an object or throws exeption. But server side functionality execute without any error. This happens for all methods calls in this server module. But there are some other server modules which works without any exception. Any idea on this issue?

Edit:- If return type is newly created class it works fine

hmc
  • 85
  • 1
  • 10

2 Answers2

0

I had this problem and did like this right now:

import org.apache.commons.io.IOUtils;

    byte[] bytes;
    try {
        bytes = IOUtils.toByteArray(uploadedFile.getInputstream());
        image.setContent(bytes);
        imageService.save(image);
    } catch (IOException ex) {
        ...
    }
axetroll
  • 319
  • 2
  • 7
0

You most likely use Java Serialization for the communication between client and server.

For Java Serialization to work correctly, both client and server need to have compatible version of class file (I also believe Java did not guarantee the serialization type to be compatible between versions, but I can't find any documentation for that now).

When you have different versions of Java, then quite likely some class might have different structure (example would be Throwable (superclass of Exception), which has new field suppressedExceptions in Java7). Normally, the serialization tries to throw meaningful exception for that, but in some cases, it might fail to do so and only throws the StreamCorruptedException.

Michal
  • 1,262
  • 1
  • 12
  • 22