Skip to content

Concurrency problem with _lastline in LCDSocketPoller #4

@antoneliasson

Description

@antoneliasson

I've observed crashes like the following:

sep 17 11:08:19 raspberrypi java[537]: Exception in thread "Thread-1" java.lang.NullPointerException
sep 17 11:08:19 raspberrypi java[537]: at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
sep 17 11:08:19 raspberrypi java[537]: at java.util.regex.Matcher.reset(Matcher.java:309)
sep 17 11:08:19 raspberrypi java[537]: at java.util.regex.Matcher.<init>(Matcher.java:229)
sep 17 11:08:19 raspberrypi java[537]: at java.util.regex.Pattern.matcher(Pattern.java:1093)
sep 17 11:08:19 raspberrypi java[537]: at org.boncey.lcdjava.LCDSocketPoller.run(LCDSocketPoller.java:90)
sep 17 11:08:19 raspberrypi java[537]: [main] INFO org.boncey.lcdjava.LCD - Connected

Looking inside LCDSocketPoller, it's clear that access to _lastline is not concurrency correct. A different thread (inside LCD) can call getLastLine, setting it to null, while the LCDSocketPoller thread is reading _lastline inside the run() loop. This can cause it to be equal to null on line 90, even though there is a not-null-check on line 87.

Using org.boncey.lcdjava 0.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions