-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Actual Behavior
Method
Java_jssc_SerialNativeInterface_writeBytes(JNIEnv*, jobject, jlong, jbyteArray);
Conceals error details.
_writeBytes just returns true/false on success/failure without any further details. But write() would provide (potentially useful) error details (For example see a list at its man page).
Further, SerialPort.writeBytes just communicates errors by returning false. This has potential to fool java developers. As they're used to get exceptions thrown if someting is wrong. Java code, checking for returned success/failure codes is something I see seldom. I even found exactly this mistake in our projects codebase which is using jssc. This is not meant to blame java devs. It's just when writing java, one easily overlooks this as one is used to exceptions and does not expect a method where the return value suddenly should be checked (in contrast of all other methods around id).
Expected Behavior
IMHO we should provide more error details to our caller. I see multiple ways to do so. Eg we could throw java exceptions (for example from SerialPort class but also from native code would be possible). Or returning numerical codes, Or providing some kind of getError() method (not very nice, but better than nothing) alongside with the returned boolean where caller can retrieve an error message. Or ... whatever.