mojira.dev
MC-263058

A newly added data storage file cannot be loaded if it was previously failed to be loaded

The bug

If a new data storage file (.dat file under the data directory) is added, it can usually be loaded successfully while the world is opened.
However, if the file was failed to be loaded previously after the world was opened, it cannot be loaded until the world is reopened.

How to reproduce

  1. Open a world

  2. Run

    /data get storage mc-263058: a
  3. Move the attached data storage file under the data directory

  4. Run

    /data get storage mc-263058: a

    → ❌ Found no elements matching a

If step 2 is skipped, the command in step 4 will succeed.

Code analysis

net/minecraft/world/level/storage/DimensionDataStorage.java

@Nullable
public <T extends SavedData> T get(Function<CompoundTag, T> load, String key) {
    SavedData data = this.cache.get(key);
    if (data == null && !this.cache.containsKey(key)) {
        data = this.readSavedData(load, key);
        this.cache.put(key, data);
    }

    return (T)data;
}

DimensionDataStorage#get attempts to read saved data when the value corresponding to the given key in the cache is null and the cache does not contain the key. Here, DimensionDataStorage#readSavedData returns null if the read fails, but this result is also cached. Once this happens, it no longer meets the latter condition, and the saved data of the key cannot be read until the world is reopened.

Attachments

Comments 1

Modifying your world data while the world is opened is not supported.

intsuc

(Unassigned)

Confirmed

(Unassigned)

1.19.4, 1.20 Pre-release 7

Retrieved