Skip to content

org.hid4java.HidDevice.read(HidDevice.java:402) java.lang.NegativeArraySizeException: -1 on read failure #156

@fricpa

Description

@fricpa

it's a bit confusing/discouraging that an error in the implementation leaks when a read fails:

2024-07-18T12:06:06,135 INFO  [org.example.Main.main()] org.example.tihidapi.impl.hid4java.TiHidApiSessionHid4JavaImplementation - writing: [63, 2, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ...
2024-07-18T12:06:06,136 TRACE [org.example.Main.main()] org.example.tihidapi.impl.hid4java.TiHidApiSessionHid4JavaImplementation - writing, as ISO/IEC 8859-1: ?.r.............................................................
> [40]: 3f 02 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2024-07-18T12:06:06,137 INFO  [org.example.Main.main()] org.example.tihidapi.impl.hid4java.TiHidApiSessionHid4JavaImplementation - reading attempt, at most for timeout=3000 ms...
2024-07-18T12:06:06,509 ERROR [org.example.Main.main()] org.example.Main - inner error, devicePath=UsbDevicePath(vendorId=0x2047, productId=0x0301, serialNumber='B4459C6F2B002100'), status=31119h,631610,451,0,0,1,0
 java.lang.RuntimeException: java.lang.NegativeArraySizeException: -1
        at org.example.tihidapi.impl.hid4java.TiHidApiSessionFactoryHid4JavaImplementation.runWithSession(TiHidApiSessionFactoryHid4JavaImplementation.java:41) ~[classes/:?]
        at org.example.apdapi.Api.read(Api.java:97) ~[classes/:?]
        at org.example.Main.main(Main.java:51) ~[classes/:?]
        at org.codehaus.mojo.exec.ExecJavaMojo.doMain(ExecJavaMojo.java:385) ~[?:?]
        at org.codehaus.mojo.exec.ExecJavaMojo.doExec(ExecJavaMojo.java:374) ~[?:?]
        at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0(ExecJavaMojo.java:296) ~[?:?]
        at java.base/java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.lang.NegativeArraySizeException: -1
        at org.hid4java.HidDevice.read(HidDevice.java:402) ~[hid4java-0.8.0.jar:0.8.0]
        at org.example.tihidapi.impl.hid4java.TiHidApiSessionHid4JavaImplementation.read(TiHidApiSessionHid4JavaImplementation.java:94) ~[classes/:?]
        at org.example.apdapi.Api.lambda$read$1(Api.java:108) ~[classes/:?]
        at org.example.tihidapi.impl.hid4java.TiHidApiSessionFactoryHid4JavaImplementation.runWithSession(TiHidApiSessionFactoryHid4JavaImplementation.java:39) ~[classes/:?]
        ... 6 more

this happened when I intentionally disconnected the device while it was being read. I would expect an IOException or something

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions