Skip to content

Method writeBytes conceals error details #96

@hiddenalpha

Description

@hiddenalpha

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions