vaadin / collaboration-engine

The simplest way to build real-time collaboration into web apps
https://vaadin.com/collaboration
Other
3 stars 1 forks source link

NullpointerException in Topic #55

Closed chrosim closed 2 years ago

chrosim commented 2 years ago

I am facing a NPE sometimes which is raised in the Topic.class More specific inside the clearExpiredData Method the namedMapData.get(name) sometimes results in a null value.

private void clearExpiredData() {
        Clock clock = collaborationEngine.getClock();
        if (lastDisconnected != null) {
            Instant now = clock.instant();
            mapExpirationTimeouts.forEach((name, timeout) -> {
                if (now.isAfter(lastDisconnected.plus(timeout))) {
                    namedMapData.get(name).clear();
                }
            });
            listExpirationTimeouts.forEach((name, timeout) -> {
                if (now.isAfter(lastDisconnected.plus(timeout))) {
                    namedListData.get(name).clear();
                }
            });
        }
        lastDisconnected = null;
    }

Versions

Legioth commented 2 years ago

Seems like this can happen in case a timeout has been set for a map (or list) that never has had any content. The map case can be tested with this variation of the regular expiration timeout test (expirationTimeout_mapClearedAfterTimeout):


@Test
public void expirationTimeout_unpopulatedMap_mapClearWithoutExplosions() {
    Duration timeout = Duration.ofMinutes(15);
    map.setExpirationTimeout(timeout);
    registration.remove();
    ce.setClock(Clock.offset(ce.getClock(), timeout.plusMinutes(1)));

    ce.openTopicConnection(context, "topic", SystemUserInfo.getInstance(), connection -> null);
    // All is fine if openTopicConnection runs successfully
}
heruan commented 2 years ago

@chrosim the issue has been fixed in Collaboration Engine 5.0.0.alpha2 which requires Vaadin 23.0.0.alpha3.

We are backporting the fix also to Collaboration Engine 3.2 and 4.0, I'll let you know once released.