[JAVA-103] ByteEncoder assumes all arrays are Object[] Created: 12/Apr/10 Updated: 29/Oct/10 Resolved: 29/Sep/10 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 1.4 |
| Fix Version/s: | 2.2 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Matt Mastracci | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 3 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| 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() ) 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. |
| Comments |
| Comment by auto [ 29/Sep/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: additional test for |
| Comment by auto [ 29/Sep/10 ] |
|
Author: {'login': '', 'name': 'hmeiser', 'email': 'hmeiser@example.com'}Message: BSONEncoder now can handle primitive arrays |
| Comment by Hans Meiser [ 29/Sep/10 ] |
|
http://github.com/theunique/mongo-java-driver/commit/e6e164c6fcadfcf9a50b4b4723ba516afeb49c85 |