Fixed stackoverflow error

This commit is contained in:
Risto Lahtela 2021-03-16 18:30:12 +02:00
parent 62da72e6f1
commit 3711f0ca60
4 changed files with 46 additions and 1 deletions

View File

@ -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() {

View File

@ -29,6 +29,10 @@ public class DataMap {
this.data = new HashMap<>();
}
private DataMap(Map<String, Object> data) {
this.data = new HashMap<>(data);
}
public <T> void put(Class<T> type, T value) {
data.put(type.getName(), value);
}
@ -57,4 +61,8 @@ public class DataMap {
"data=" + data +
'}';
}
public DataMap copy() {
return new DataMap(data);
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -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<String> 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;