4 Replies Latest reply on Jun 20, 2006 10:57 AM by mazz

    StreamHandler index out of bounds

    mazz Master

      I'm starting to use the streaming capabilities in remoting. I think I hit a bug in StreamHandler. Here's the stack trace I am seeing:

      22:08:56,632 ERROR [SocketServerInvokerThread-127.0.0.1-11] (org.jboss.remoting.
      stream.StreamHandler) - Error reading with offset from client stream.
      java.lang.ArrayIndexOutOfBoundsException
       at java.lang.System.arraycopy(Native Method)
       at org.jboss.remoting.stream.StreamHandler.read(StreamHandler.java:491)
       at java.io.BufferedInputStream.read1(BufferedInputStream.java:254)
       at java.io.BufferedInputStream.read(BufferedInputStream.java:313)
       at java.io.FilterInputStream.read(FilterInputStream.java:90)
      ...
      


      Looking at like 491:

      System.arraycopy(retBytes, 0, b, off, retByte);


      I find that in my instance, retByte is -1 (stepping thru it in the debugger). As per javadoc, an index OOB exception is thrown by arraycopy() if length is negative as the case is here.

        • 1. Re: StreamHandler index out of bounds
          mazz Master

          Forgot some other things.

          First, I can see data in the stream - in the debugger, I see the full data get copied via arraycopy() when I put a breakpoint on that line. Its only when I reach the end of the stream do I then get this exception. So, I can see something looping on the read() - the first time through its OK, the second time into this read() method fails since the stream has reached EOF.

          Second, my testing is a bit unusual - my client and server are both running in the same VM. I don't know if that matters, but I mention it just in case.

          • 2. Re: StreamHandler index out of bounds
            Tom Elrod Master

            Don't guess you have a test case for this? Even just the code in the handler will do (need to see how you are using the StreamHandler). Also, did you try using the server invoker handler code directly on the original stream (bypassing remoting)? Just curious how it behaves in that case.

            http://jira.jboss.com/jira/browse/JBREM-506

            • 3. Re: StreamHandler index out of bounds
              mazz Master

              No test case that you can use directly.

              Also I'm not using StreamHandler directly. I am creating my own InputStream (a ByteArrayInputStream to be exact), passing it to Client.invoke(InputStream, Object), which in turn makes it way to the handler on the server side. I then have my handler read the stream like any normal stream which is when I get this exception.

              On the handler side, I just operate on an "InputStream" (which is implicitly a StreamHandler I believe - I'm just working on the input stream given to StreamInvocationHandler.handleStream(InputStream, InvocationRequest).

              Here's psuedo-code of my test on the client side:

               String stream_data = "Stream this string!!!";
               InputStream in = new ByteArrayInputStream( stream_data.getBytes() );
               results = getJBossRemotingClient().invoke( in, myParam);
              


              and on the server side:

               public handleStream(InputStream in, InvocationRequest req)
               {
               byte[] stream_data = readEntireStream(in);
               }
              


              • 4. Re: StreamHandler index out of bounds
                mazz Master

                See the JIRA issue for the fix. I changed it such that the arraycopy() call is not made if the retByte is not greater than 0. That fixes me and I work successfully now.