Spot the bug in the HashMap record key

from Records
Java 25 LTS intermediate 4 min 1 issue to find

Find why this record is unsafe as a HashMap key.

Java
import java.util.HashMap;
import java.util.List;

public class Main {
    record Route(List<String> stops) {}

    public static void main(String[] args) {
        var stops = new java.util.ArrayList<>(List.of("A", "B"));
        var route = new Route(stops);
        var index = new HashMap<Route, String>();
        index.put(route, "morning");
        stops.add("C");
        System.out.println(index.get(route));
    }
}
Open in playground
Report an error