Skip to content

Commit fbbd950

Browse files
committed
#457: fixed exception throw method call; moved common operand handling to finally block
1 parent 62d6697 commit fbbd950

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

src/org/aavso/tools/vstar/vela/Operand.java

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -320,41 +320,40 @@ public static Operand object2Operand(Type type, Object obj) {
320320
case LIST:
321321
List<Operand> arr = new ArrayList<Operand>();
322322

323-
if (obj.getClass() == Type.FLOAT_ARR.getClass()) {
324-
for (float n : (float[]) obj) {
325-
arr.add(new Operand(Type.REAL, n));
323+
try {
324+
if (obj.getClass() == Type.FLOAT_ARR.getClass()) {
325+
for (float n : (float[]) obj) {
326+
arr.add(new Operand(Type.REAL, n));
327+
}
328+
} else if (obj.getClass() == Type.DBL_ARR.getClass()) {
329+
for (double n : (double[]) obj) {
330+
arr.add(new Operand(Type.REAL, n));
331+
}
332+
} else if (obj.getClass() == Type.DBL_CLASS_ARR.getClass()) {
333+
for (Double n : (Double[]) obj) {
334+
arr.add(new Operand(Type.REAL, n));
335+
}
336+
} else if (obj.getClass() == Type.INT_ARR.getClass()) {
337+
for (int n : (int[]) obj) {
338+
arr.add(new Operand(Type.INTEGER, n));
339+
}
340+
} else if (obj.getClass() == Type.LONG_ARR.getClass()) {
341+
for (long n : (long[]) obj) {
342+
arr.add(new Operand(Type.INTEGER, n));
343+
}
344+
} else if (obj.getClass() == Type.BOOL_ARR.getClass()) {
345+
for (boolean b : (boolean[]) obj) {
346+
arr.add(new Operand(Type.BOOLEAN, b));
347+
}
348+
} else if (obj.getClass() == Type.STR_ARR.getClass()) {
349+
for (String s : (String[]) obj) {
350+
arr.add(new Operand(Type.STRING, s));
351+
}
326352
}
327-
operand = new Operand(Type.LIST, arr);
328-
} else if (obj.getClass() == Type.DBL_ARR.getClass()) {
329-
for (double n : (double[]) obj) {
330-
arr.add(new Operand(Type.REAL, n));
353+
} finally {
354+
if (!arr.isEmpty()) {
355+
operand = new Operand(Type.LIST, arr);
331356
}
332-
operand = new Operand(Type.LIST, arr);
333-
} else if (obj.getClass() == Type.DBL_CLASS_ARR.getClass()) {
334-
for (Double n : (Double[]) obj) {
335-
arr.add(new Operand(Type.REAL, n));
336-
}
337-
operand = new Operand(Type.LIST, arr);
338-
} else if (obj.getClass() == Type.INT_ARR.getClass()) {
339-
for (int n : (int[]) obj) {
340-
arr.add(new Operand(Type.INTEGER, n));
341-
}
342-
operand = new Operand(Type.LIST, arr);
343-
} else if (obj.getClass() == Type.LONG_ARR.getClass()) {
344-
for (long n : (long[]) obj) {
345-
arr.add(new Operand(Type.INTEGER, n));
346-
}
347-
operand = new Operand(Type.LIST, arr);
348-
} else if (obj.getClass() == Type.BOOL_ARR.getClass()) {
349-
for (boolean b : (boolean[]) obj) {
350-
arr.add(new Operand(Type.BOOLEAN, b));
351-
}
352-
operand = new Operand(Type.LIST, arr);
353-
} else if (obj.getClass() == Type.STR_ARR.getClass()) {
354-
for (String s : (String[]) obj) {
355-
arr.add(new Operand(Type.STRING, s));
356-
}
357-
operand = new Operand(Type.LIST, arr);
358357
}
359358
break;
360359
case FUNCTION:
@@ -432,7 +431,7 @@ public Object toObject(Class<?> javaType) {
432431
obj = strings;
433432
}
434433
} catch (Exception e) {
435-
java2VeLaTypeError(obj.getClass(), type);
434+
vela2JavaTypeError(this, javaType);
436435
}
437436
break;
438437
case FUNCTION:

0 commit comments

Comments
 (0)