Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-1506

CDROutputStream.create_input_stream is wrong when there are deferred writes

XMLWordPrintable

      An exception is thrown when trying to insert a byte[] larger than 4000 bytes into any any:

      package test;

      import java.util.Properties;
      import org.omg.CORBA.ORB;
      import org.omg.CORBA.Any;
      import org.omg.CORBA.OctetSeqHelper;

      public class Test
      {
      public static final void main(String[] args)
      {
      System.out.println("*** Starting test ***");

      try

      { Properties props = new Properties(); props.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB"); props.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton"); ORB orb = ORB.init(args, props); byte[] bytes = new byte[4001]; Any any = orb.create_any(); OctetSeqHelper.insert(any, bytes); }

      catch (Exception e)

      { e.printStackTrace(); }

      }
      }
      ===================================================
      [java] *** Starting test ***
      [java] [ jacorb.home unset! Will use '.' ]
      [java] [ File .\jacorb.properties for configuration jacorb not found ]
      [java] java.lang.ArrayIndexOutOfBoundsException
      [java] at java.lang.System.arraycopy(Native Method)
      [java] at org.jacorb.orb.CDROutputStream.create_input_stream(Unknown So
      urce)
      [java] at org.omg.CORBA.OctetSeqHelper.insert(OctetSeqHelper.java:41)
      [java] at test.Test.main(Test.java:24)
      =======================================================

      With a byte[] of size 4000 or less, it works!

      I've noticed that the exception actually originates from the Helper class that comes from Sun's JDK:

      ...
      public abstract class OctetSeqHelper
      {
      private static String _id = "IDL:omg.org/CORBA/OctetSeq:1.0";

      public static void insert (org.omg.CORBA.Any a, byte[] that)

      { org.omg.CORBA.portable.OutputStream out = a.create_output_stream (); a.type (type ()); write (out, that); a.read_value (out.create_input_stream (), type ()); }

      The same class from the jacorb distribution does not perform that final "a.read_value(...)" line that causes the exception:

      public static void insert (org.omg.CORBA.Any any, byte[] s)

      { any.type (type ()); write (any.create_output_stream (), s); }

      public static void write (final org.omg.CORBA.portable.OutputStream _out, byte[] _s)

      { _out.write_long(_s.length); _out.write_octet_array(_s,0,_s.length); }

      Also, if you look into jacorb's CDROutputStream, there is somewhere a hardcoded 4000 limit:

      public final void write_octet_array( final byte[] value,
      final int offset,
      final int length)
      {
      if( value != null )
      {
      if( length > 4000 )

      { deferredArrayQueue.add( new DeferredWriteFrame( index, offset, length, value )); index += length; deferred_writes += length; }

      else

      { check(length); System.arraycopy(value,offset,buffer,pos,length); index += length; pos += length; }

      }
      }

              dandread1@redhat.com Dimitrios Andreadis
              dandread1@redhat.com Dimitrios Andreadis
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 days
                  2d