Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate Key - misleading exception information? [duplicate]

What is the reason of the exception message complains about duplicate key but shows the value instead?

List<Employee> employees = new ArrayList<>();
employees.add(new Employee("John", 40));
employees.add(new Employee("John", 30));

Map<String, Integer> map = employees.stream()
    .collect(Collectors.toMap(Employee::getName, Employee::getAge));

Instead of show "John" as the duplicated key, it show "40"

Exception in thread "main" java.lang.IllegalStateException: Duplicate key 40
    (...)
like image 518
VeryNiceArgumentException Avatar asked Nov 22 '18 11:11

VeryNiceArgumentException


1 Answers

It has been fixed in JDK 9. Take a look here. https://bugs.openjdk.java.net/browse/JDK-8173464

like image 58
vinay khurana Avatar answered Oct 27 '22 14:10

vinay khurana