SuppressedExceptionCollector .java

net.minecraft.server.SuppressedExceptionCollector (class): members: LATEST_ENTRY_COUNT, latestEntries, entryCounts, ShortEntry, LongEntry, dump, addEntry.

net.minecraft.serverclass73 linesserver2.5 KB

API Surface (2)

void addEntry(final String location, final Throwable throwable)
String dump()

Fields & Constants (3)

LATEST_ENTRY_COUNT
latestEntries
entryCounts

String literals (4)

"\n\t\tLatest entries:\n"
"ms ago)"
"\t\tEntry counts:\n"
"~~NONE~~"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SuppressedExceptionCollector.java73 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server;
2
3
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
4
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
5
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
6
import java.util.Queue;
7
import net.minecraft.util.ArrayListDeque;
8
9
public class SuppressedExceptionCollector {
10
	private static final int LATEST_ENTRY_COUNT = 8;
11
	private final Queue<SuppressedExceptionCollector.LongEntry> latestEntries = new ArrayListDeque<>();
12
	private final Object2IntLinkedOpenHashMap<SuppressedExceptionCollector.ShortEntry> entryCounts = new Object2IntLinkedOpenHashMap<>();
13
14
	private static long currentTimeMs() {
15
		return System.currentTimeMillis();
16
	}
17
18
	public synchronized void addEntry(final String location, final Throwable throwable) {
19
		long now = currentTimeMs();
20
		String message = throwable.getMessage();
21
		this.latestEntries.add(new SuppressedExceptionCollector.LongEntry(now, location, (Class<? extends Throwable>)throwable.getClass(), message));
22
23
		while (this.latestEntries.size() > 8) {
24
			this.latestEntries.remove();
25
		}
26
27
		SuppressedExceptionCollector.ShortEntry key = new SuppressedExceptionCollector.ShortEntry(location, (Class<? extends Throwable>)throwable.getClass());
28
		int currentValue = this.entryCounts.getInt(key);
29
		this.entryCounts.putAndMoveToFirst(key, currentValue + 1);
30
	}
31
32
	public synchronized String dump() {
33
		long current = currentTimeMs();
34
		StringBuilder result = new StringBuilder();
35
		if (!this.latestEntries.isEmpty()) {
36
			result.append("\n\t\tLatest entries:\n");
37
38
			for (SuppressedExceptionCollector.LongEntry e : this.latestEntries) {
39
				result.append("\t\t\t")
40
					.append(e.location)
41
					.append(":")
42
					.append(e.cls)
43
					.append(": ")
44
					.append(e.message)
45
					.append(" (")
46
					.append(current - e.timestampMs)
47
					.append("ms ago)")
48
					.append("\n");
49
			}
50
		}
51
52
		if (!this.entryCounts.isEmpty()) {
53
			if (result.isEmpty()) {
54
				result.append("\n");
55
			}
56
57
			result.append("\t\tEntry counts:\n");
58
59
			for (Entry<SuppressedExceptionCollector.ShortEntry> e : Object2IntMaps.fastIterable(this.entryCounts)) {
60
				result.append("\t\t\t").append(e.getKey().location).append(":").append(e.getKey().cls).append(" x ").append(e.getIntValue()).append("\n");
61
			}
62
		}
63
64
		return result.isEmpty() ? "~~NONE~~" : result.toString();
65
	}
66
67
	private record LongEntry(long timestampMs, String location, Class<? extends Throwable> cls, String message) {
68
	}
69
70
	private record ShortEntry(String location, Class<? extends Throwable> cls) {
71
	}
72
}
73

Decompiled Minecraft 26.3 source of SuppressedExceptionCollector (net/minecraft/server/SuppressedExceptionCollector.java) with Mojang official mappings, stored verbatim on the site.