Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-103

ByteEncoder assumes all arrays are Object[]

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2
    • Affects Version/s: 1.4
    • Component/s: None
    • Labels:
      None
    • Environment:
      Java
    • Major Change

      The ByteEncoder class assumes that if a value isArray(), the array type is Object. This throws a ClassCastException if you attempt to pass a primitive array:

      else if ( val.getClass().isArray() )
      putList( name , Arrays.asList( (Object[])val ) );

      It would be more flexible to use Array.get() to reflectively read the array:

      private void putArray( String name , Object array )

      { _put( ARRAY , name ); final int sizePos = _buf.position(); _buf.putInt( 0 ); int size = Array.getLength(array); for ( int i=0; i<size; i++ ) _putObjectField( String.valueOf( i ) , Array.get( array, i ) ); _buf.put( EOO ); _buf.putInt( sizePos , _buf.position() - sizePos ); }

      I can provide a patch, if needed.

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            mmastrac Matt Mastracci
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: