diff --git a/Integrations/src/main/java/io/deephaven/integrations/python/PythonValueGetter.java b/Integrations/src/main/java/io/deephaven/integrations/python/PythonValueGetter.java index 9319688b2cd..da2349816c2 100644 --- a/Integrations/src/main/java/io/deephaven/integrations/python/PythonValueGetter.java +++ b/Integrations/src/main/java/io/deephaven/integrations/python/PythonValueGetter.java @@ -49,21 +49,33 @@ static int getInt(PyObject valueIn) { if (valueIn == null) { return QueryConstants.NULL_INT; } - return valueIn.getIntValue(); + long ll = valueIn.getLongValue(); + if ((int) ll != ll) { + throw new ArithmeticException("The PyObject value is outside Integer range."); + } + return (int) ll; } static short getShort(PyObject valueIn) { if (valueIn == null) { - return QueryConstants.NULL_SHORT; + return QueryConstants.NULL_SHORT; // NB: should there be a getShortValue() in jpy? + } + long ll = valueIn.getLongValue(); + if ((short) ll != ll) { + throw new ArithmeticException("The PyObject value is outside Short range."); } - return (short) valueIn.getIntValue(); // NB: should there be a getShortValue() in jpy? + return (short) ll; } static byte getByte(PyObject valueIn) { if (valueIn == null) { return QueryConstants.NULL_BYTE; // NB: should there be a getByteValue() in jpy? } - return (byte) valueIn.getIntValue(); + long ll = valueIn.getLongValue(); + if ((byte) ll != ll) { + throw new ArithmeticException("The PyObject value is outside Byte range."); + } + return (byte) ll; } static Boolean getBoolean(PyObject valueIn) {