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

ByteEncoder assumes all arrays are Object[]

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.2
    • 1.4
    • None
    • None
    • Java
    • Major Change

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: