Skip to content

P1.memo() sometimes returns null when accessed concurrently #105

Description

@mperry

Paweł Krupiński reported an issue in the group as per below (https://groups.google.com/forum/#!topic/functionaljava/nSPIBAvAWVY):

Hi.
We started noticing NullPointerExceptions in our code that accessed fj.data.Stream instances concurrently.

I was able to trace it down to P1.memo() creating a P1 that sometimes returns null from ._1() call when accessed concurrently.
Here's how to reproduce it (sometimes you need to run it multiple times) on Java 8 and functionaljava 4.2:

final P1<String> p1 = P.p("Bla").memo();
ExecutorService executorService = Executors.newCachedThreadPool();
for (int i = 0; i < 1000; i++) {
    executorService.submit(() -> {
        if (p1._1() == null) {
            System.out.println("Null");
        }
    });
}

executorService.shutdown();
executorService.awaitTermination(10, TimeUnit.DAYS);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions