diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/ActiveSession.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/ActiveSession.java index 233380b6c..77ca82f26 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/ActiveSession.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/ActiveSession.java @@ -56,7 +56,7 @@ public class ActiveSession { } public FinishedSession toFinishedSession(long end) { - return new FinishedSession(playerUUID, serverUUID, start, end, afkTime, extraData); + return new FinishedSession(playerUUID, serverUUID, start, end, afkTime, extraData.copy()); } public UUID getPlayerUUID() { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/DataMap.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/DataMap.java index 5cd51803d..6f17595d3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/DataMap.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/domain/DataMap.java @@ -29,6 +29,10 @@ public class DataMap { this.data = new HashMap<>(); } + private DataMap(Map data) { + this.data = new HashMap<>(data); + } + public void put(Class type, T value) { data.put(type.getName(), value); } @@ -57,4 +61,8 @@ public class DataMap { "data=" + data + '}'; } + + public DataMap copy() { + return new DataMap(data); + } } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/gathering/domain/ActiveSessionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/gathering/domain/ActiveSessionTest.java new file mode 100644 index 000000000..1ac8b125b --- /dev/null +++ b/Plan/common/src/test/java/com/djrapitops/plan/gathering/domain/ActiveSessionTest.java @@ -0,0 +1,35 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan.gathering.domain; + +import org.junit.jupiter.api.Test; +import utilities.RandomData; +import utilities.TestConstants; + +class ActiveSessionTest { + + @Test + void noStackOverflowErrorFromFinishingSession() { + ActiveSession session = RandomData.randomUnfinishedSession(TestConstants.SERVER_UUID, TestConstants.WORLDS, TestConstants.PLAYER_ONE_UUID, TestConstants.PLAYER_TWO_UUID); + + FinishedSession finishedSession = session.toFinishedSession(System.currentTimeMillis()); + + session.hashCode(); // Error was here + finishedSession.hashCode(); + } + +} \ No newline at end of file diff --git a/Plan/common/src/test/java/utilities/TestConstants.java b/Plan/common/src/test/java/utilities/TestConstants.java index 6cd9cc167..3824a1e16 100644 --- a/Plan/common/src/test/java/utilities/TestConstants.java +++ b/Plan/common/src/test/java/utilities/TestConstants.java @@ -28,6 +28,7 @@ import java.util.function.Supplier; */ public class TestConstants { + private TestConstants() { /* Static variable class */ } @@ -47,6 +48,7 @@ public class TestConstants { public static final Supplier PLAYER_HOSTNAME = () -> "play.example.com"; public static final String WORLD_ONE_NAME = "World One"; + public static final String[] WORLDS = new String[]{WORLD_ONE_NAME}; public static final Long REGISTER_TIME = RandomData.randomTime(); public static final int SERVER_MAX_PLAYERS = 20;