Skip to content

Exception about removeEventListener #123

Open

Description

@HughWick

I tried to remove the EventListener after getting the serialPort object in another class and found an exception, the final reason is that I did not add the EventListener beforehand, I tried to use the getEventListener (there is no such method)
or
the getEventListenerAdded flag

//but the variable is private
 private boolean eventListenerAdded = false;

to get if there is currently an EventListener event.

Is there something I'm doing wrong?

Can you add a flag function to get whether there is currently an EventListener in the next version

Activity

  1. added
    bugSomething isn't working
    on Jan 9, 2025
  2. tresf commented on Jan 9, 2025

    @tresf

    This should be fixed once #181 is merged. We removed the boolean that tracked the listener and instead check to see if the thread is active, which avoids trying to track the lifecycle in a separate variable. This means that if a listener (i.e. eventThread) isn't active, the function will simply return false which can be use to assume that no listener was ever added.

    The old logic had several flaws, but the main flaw was that it would raise an exception if the port was not opened. To that point, I believe #181 also suffers this problem, because in the event a listener was added but the port was closed, we'll never get to eventThread.join(5000);. @Vzor- I believe this may be another candidate for a try/finally. Once we have this fixed, we can update #181 to close this bug report as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions