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

ByteEncoder assumes all arrays are Object[]

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Java
    • Backwards Compatibility:
      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

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

              Dates

              Created:
              Updated:
              Resolved: