From ac982f6d8d444bebb27d2c30024f4db2e19fdab6 Mon Sep 17 00:00:00 2001 From: Christopher Buckley <15166572+topherbuckley@users.noreply.github.com> Date: Tue, 1 Jun 2021 12:13:01 +0900 Subject: [PATCH] replaced assert keyword with RuntimeExceptions for analog and digital input setValue methods --- IOIOLibCore/src/main/java/ioio/lib/impl/AnalogInputImpl.java | 4 +++- IOIOLibCore/src/main/java/ioio/lib/impl/DigitalInputImpl.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/IOIOLibCore/src/main/java/ioio/lib/impl/AnalogInputImpl.java b/IOIOLibCore/src/main/java/ioio/lib/impl/AnalogInputImpl.java index dedc6e0f4..1c501ad65 100644 --- a/IOIOLibCore/src/main/java/ioio/lib/impl/AnalogInputImpl.java +++ b/IOIOLibCore/src/main/java/ioio/lib/impl/AnalogInputImpl.java @@ -66,7 +66,9 @@ public float getReference() { @Override synchronized public void setValue(int value) { // Log.v("AnalogInputImpl", "Pin " + pinNum_ + " value is " + value); - assert (value >= 0 && value < 1024); + if (value < 0 || value >= 1024) { + throw new RuntimeException("value must be between 0 (inclusive) and 1024 (exclusive). A value of " + value + " was given."); + } value_ = value; ++sampleCount_; bufferPush((short) value); diff --git a/IOIOLibCore/src/main/java/ioio/lib/impl/DigitalInputImpl.java b/IOIOLibCore/src/main/java/ioio/lib/impl/DigitalInputImpl.java index 5f498acb6..e84448b15 100644 --- a/IOIOLibCore/src/main/java/ioio/lib/impl/DigitalInputImpl.java +++ b/IOIOLibCore/src/main/java/ioio/lib/impl/DigitalInputImpl.java @@ -47,7 +47,9 @@ class DigitalInputImpl extends AbstractPin implements DigitalInput, @Override synchronized public void setValue(int value) { // Log.v("DigitalInputImpl", "Pin " + pinNum_ + " value is " + value); - assert (value == 0 || value == 1); + if (value != 0 && value != 1) { + throw new RuntimeException("value must be 0 or 1. A value of " + value + " was given."); + } value_ = (value == 1); if (!valid_) { valid_ = true;