Skip to content

Commit dad61cd

Browse files
committed
WIP: Only convert to array types when it is possible
1 parent 9564503 commit dad61cd

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/main/java/org/scijava/convert/DefaultConverter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ 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+
if (isArray(dest)){
296+
if (Collection.class.isAssignableFrom(src)) return true;
297+
if (src.isArray()) return true;
298+
return Types.isAssignable(src, Types.component(dest));
299+
}
296300

297301
// Handle parameterized collection types.
298302
if (dest instanceof ParameterizedType && isCollection(dest) &&

src/test/java/org/scijava/convert/ConvertServiceTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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");

0 commit comments

Comments
 (0)