Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Bad exception thrown when interrupted in I2C read #407

Open
RenWal opened this issue Apr 1, 2018 · 1 comment
Open

Bad exception thrown when interrupted in I2C read #407

RenWal opened this issue Apr 1, 2018 · 1 comment
Assignees
Milestone

Comments

@RenWal
Copy link

RenWal commented Apr 1, 2018

Hello!

There is an issue with the Pi4J I2C implementation that keeps crashing my application on shutdown:
Whenever there is an I2C read waiting to obtain the bus access lock and the thread is interrupted, the I2CBusImpl class catches the InterruptedException thrown by the tryLock() method and wraps it in a RuntimeException.
Unexpecting callers will have no idea what has just happened, probably not have a good handler for it or even just crash the thread entirely with an uncaught runtime exception.
Instead, after logging, the InterruptedException should just be re-thrown, so that callers clearly see that the method has failed because of an interrupt and can act accordingly.

https://github.com/Pi4J/pi4j/blob/f4a3f790a3be9d419d89525cedadffbad602a9c4/pi4j-core/src/main/java/com/pi4j/io/i2c/impl/I2CBusImpl.java#L267

Workaround is to put a catch block for RuntimeException on the caller's side and then check if getCause() returns an object of type InterruptedException.

@savageautomate savageautomate self-assigned this Jan 15, 2021
@savageautomate savageautomate added this to the RELEASE 1.4 milestone Jan 15, 2021
@savageautomate
Copy link
Member

Reviewing this issue for v1.4 release. While I agree the exception probably should not be caught internally and masked as a runtime exception, changing this behavior would be a breaking API change for most of the I2CDevice methods.

Postponing fix to version 2.0 where breaking API changes are planned.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants