Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible bug found #2

Closed
JuanAntonioNazabal opened this issue Feb 10, 2016 · 3 comments

Comments

@JuanAntonioNazabal
Copy link

commented Feb 10, 2016

Hello,
I used you library and had some problems when I was reading from the InputStream retrieved from the SerialPort and at the same time catched an InterruptedException. I believe that the problem is in the read method from the class BufferedSerialInputStream. When an InterruptedException is catched, you only print the exception but I believe that you should restore the interrupted status after catching InterruptedException. So, changing the code "e.printStackTrace();" with the following code "Thread.currentThread().interrupt();" seems to fix the problem.
Best regards,
Juanan

@rm5248 rm5248 self-assigned this Feb 10, 2016
@rm5248

This comment has been minimized.

Copy link
Owner

commented Feb 10, 2016

Thanks! It does look like that could cause a problem. I have never encountered an InterruptedException before, so I just printed the stack trace without thinking about it too much.

Links for reference:

@rm5248

This comment has been minimized.

Copy link
Owner

commented Feb 14, 2016

Okay, so I've taken a look at it, and there's a few things that we can do here to fix it.

  1. Throw an IOException when an InterruptedException occurs.
  2. Ignore it and attempt to read from the buffer again.

It seems that number 2 is the general way to do it using an InputStream. What probably makes the most sense here is to have a flag on the SerialPort which allows you to choose between these two methods, with option number 2 being the default.

I also noticed that at least on Windows, when the SerialPort is closed you will get an erroneous 0 back from the InputStream, instead of -1. See issue #3 for more information on that.

rm5248 added a commit that referenced this issue Feb 15, 2016
Updated BufferedSerialInputStream to optionally throw an IOException
when an InterruptedException is thrown.  Added a function on the
SerialPort to set this functionality.  Fixed the inputstream returning 0
when the serial port is closed(at least on Windows), will now return -1.
Needs to be tested on Linux.  POM should no longer try to sign by
default, only when we release.
@rm5248

This comment has been minimized.

Copy link
Owner

commented Mar 5, 2016

Should be fixed with 0.7.

@rm5248 rm5248 closed this Mar 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.