Skip to content

Commit 80943be

Browse files
committed
Update 8756: fix core/utils unit test
1 parent 2c6f291 commit 80943be

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

core/src/main/java/com/cloud/agent/transport/ArrayTypeAdaptor.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@ public T[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContex
7575
try {
7676
clazz = Class.forName(name);
7777
} catch (ClassNotFoundException e) {
78-
throw new CloudRuntimeException("can't find " + name);
78+
throw new JsonParseException("can't find " + name);
7979
}
8080
T cmd = (T)_gson.fromJson(entry.getValue(), clazz);
8181
cmds.add(cmd);
8282
}
83-
Class<?> type = ((Class<?>)typeOfT).getComponentType();
84-
T[] ts = (T[])Array.newInstance(type, cmds.size());
85-
return cmds.toArray(ts);
83+
try {
84+
Class<?> type = Class.forName(typeOfT.getTypeName().replace("[]", ""));
85+
T[] ts = (T[])Array.newInstance(type, cmds.size());
86+
return cmds.toArray(ts);
87+
} catch (ClassNotFoundException e) {
88+
throw new CloudRuntimeException("can't find " + typeOfT.getTypeName());
89+
}
8690
}
8791
}

utils/src/test/java/com/cloud/utils/LogUtilsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class LogUtilsTest {
2424

2525
@Test
2626
public void logGsonWithoutExceptionTestLogCorrectlyPrimitives() {
27-
String expected = "test primitives: int [1], double [1.11], float [1.2222], boolean [true], null [], char [\"c\"].";
27+
String expected = "test primitives: int [1], double [1.11], float [1.2222], boolean [true], null [null], char [\"c\"].";
2828
String log = LogUtils.logGsonWithoutException("test primitives: int [%s], double [%s], float [%s], boolean [%s], null [%s], char [%s].",
2929
1, 1.11d, 1.2222f, true, null, 'c');
3030
assertEquals(expected, log);

0 commit comments

Comments
 (0)