-
Bug
-
Resolution: Unresolved
-
None
-
Minecraft 18w07c, Minecraft 18w08a, Minecraft 18w08b, Minecraft 18w09a, Minecraft 18w10c, Minecraft 18w10d, Minecraft 18w11a, Minecraft 18w21a, Minecraft 18w21b, Minecraft 18w22a, Minecraft 18w22b, Minecraft 18w22c, Minecraft 1.13-pre1, Minecraft 1.13-pre2, Minecraft 1.13-pre3, Minecraft 1.13-pre4, Minecraft 1.13-pre5, Minecraft 1.13-pre6, Minecraft 1.13-pre7, Minecraft 1.13-pre8, Minecraft 1.13-pre9, Minecraft 1.13-pre10, Minecraft 1.13, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 18w45a, Minecraft 18w46a, Minecraft 19w08b, Minecraft 19w09a, Minecraft 19w14b, Minecraft 1.14.2, Minecraft 1.14.3 Pre-Release 2, Minecraft 1.14.3 Pre-Release 3, 1.14.4, 19w35a, 19w36a, 19w37a, 1.16.5, 21w07a, 1.17.1
-
Windows 10 Pro, Java 1.8.0_151
-
Confirmed
-
UI
-
Normal
-
Platform
The bug
A few Minecraft servers display "Pinging..." followed by "Can't connect to server", occasionally. This appears to happen when opening the multiplayer/server list for the first time or after the minecraft client startup or when refreshed the multiplayer server lists.
Code analysis
It appears that most parts of the code analysis of MC-73207 apply again. There has been some refactoring (LazyLoadBase uses a Supplier now) which likely replaced the fix by accident.
The following class might be a better replacement for or addition to the LazyLoadBase class. The only restriction is that the factory should be thread-safe.
public class ThreadSafeLazySupplier<T> implements Supplier<T> { private final Supplier<T> factory; private final Object valueCreationMonitor; private volatile boolean hasValue; private volatile T value; public ThreadSafeLazySupplier(final Supplier<T> factory) { this.factory = factory; valueCreationMonitor = new Object(); hasValue = false; } @Override public T get() { if (!hasValue) { synchronized(valueCreationMonitor) { if (!hasValue) { value = factory.get(); hasValue = true; } } } return value; } }