File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed
main/java/org/scijava/convert Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -292,7 +292,17 @@ private Collection<Object> createCollection(final Class<?> type) {
292292 public boolean canConvert (final Class <?> src , final Type dest ) {
293293
294294 // Handle array types, including generic array types.
295- if (isArray (dest )) return true ;
295+ // The logic follows from the types that ArrayUtils.toCollection
296+ // can convert
297+ if (isArray (dest )){
298+ // toCollection handles any type of Collection
299+ if (Collection .class .isAssignableFrom (src )) return true ;
300+ // toCollection handles any type of array
301+ if (src .isArray ()) return true ;
302+ // toCollection can wrap objects into a Singleton list,
303+ // but we only want to wrap up a T if the dest type is a T[].
304+ return Types .isAssignable (src , Types .component (dest ));
305+ }
296306
297307 // Handle parameterized collection types.
298308 if (dest instanceof ParameterizedType && isCollection (dest ) &&
Original file line number Diff line number Diff line change @@ -457,7 +457,7 @@ class Struct {
457457 /**
458458 * Tests setting an incompatible element value for a primitive array.
459459 */
460- @ Test ( expected = IllegalArgumentException . class )
460+ @ Test
461461 public void testBadPrimitiveArray () {
462462 class Struct {
463463
@@ -467,6 +467,7 @@ class Struct {
467467 final Struct struct = new Struct ();
468468
469469 setFieldValue (struct , "intArray" , "not an int array" );
470+ assertEquals (null , struct .intArray );
470471 }
471472
472473 /**
@@ -486,7 +487,7 @@ class Struct {
486487
487488 // Test abnormal behavior for an object array
488489 setFieldValue (struct , "doubleArray" , "not a double array" );
489- assertEquals (null , struct .doubleArray [ 0 ] );
490+ assertEquals (null , struct .doubleArray );
490491
491492 // Test abnormal behavior for a list
492493 setFieldValue (struct , "nestedArray" , "definitely not a set of char arrays" );
Original file line number Diff line number Diff line change @@ -237,7 +237,6 @@ class Struct {
237237 /**
238238 * Tests setting an incompatible element value for a primitive array.
239239 */
240- @ Test (expected = IllegalArgumentException .class )
241240 public void testBadPrimitiveArray () {
242241 class Struct {
243242
@@ -247,6 +246,7 @@ class Struct {
247246 final Struct struct = new Struct ();
248247
249248 setFieldValue (struct , "intArray" , "not an int array" );
249+ assertEquals (null , struct .intArray );
250250 }
251251
252252 /**
@@ -266,7 +266,7 @@ class Struct {
266266
267267 // Test abnormal behavior for an object array
268268 setFieldValue (struct , "doubleArray" , "not a double array" );
269- assertEquals (null , struct .doubleArray [ 0 ] );
269+ assertEquals (null , struct .doubleArray );
270270
271271 // Test abnormal behavior for a list
272272 setFieldValue (struct , "nestedArray" , "definitely not a set of char arrays" );
You can’t perform that action at this time.
0 commit comments