-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
8, 9
-
generic
-
generic
A DESCRIPTION OF THE REQUEST :
for test example:
@Test
public void test() {
List<String> strings = Arrays.asList("one","two");
Map<String, String> collect = strings.stream().collect(Collectors.toMap(o -> "test", String::toString));
}
Exectuion will throw "java.lang.IllegalStateException: Duplicate key one"
JUSTIFICATION :
This message is misleading because developer could think that key "one" is duplicated in result of Collectors.toMap. There is no information about which key is duplicated or which values have the same key. This problem occured in my team when we compute complicated models with many stream operations.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Message should inform which key is duplicated for example "Duplicate key: test" or which values have the same key: "Values one and two have the same key: test"
ACTUAL -
Exception message is java.lang.IllegalStateException: Duplicate key one
---------- BEGIN SOURCE ----------
@Test
public void test() {
List<String> strings = Arrays.asList("one","two");
Map<String, String> collect = strings.stream().collect(Collectors.toMap(o -> "test", String::toString));
}
---------- END SOURCE ----------
for test example:
@Test
public void test() {
List<String> strings = Arrays.asList("one","two");
Map<String, String> collect = strings.stream().collect(Collectors.toMap(o -> "test", String::toString));
}
Exectuion will throw "java.lang.IllegalStateException: Duplicate key one"
JUSTIFICATION :
This message is misleading because developer could think that key "one" is duplicated in result of Collectors.toMap. There is no information about which key is duplicated or which values have the same key. This problem occured in my team when we compute complicated models with many stream operations.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Message should inform which key is duplicated for example "Duplicate key: test" or which values have the same key: "Values one and two have the same key: test"
ACTUAL -
Exception message is java.lang.IllegalStateException: Duplicate key one
---------- BEGIN SOURCE ----------
@Test
public void test() {
List<String> strings = Arrays.asList("one","two");
Map<String, String> collect = strings.stream().collect(Collectors.toMap(o -> "test", String::toString));
}
---------- END SOURCE ----------
- duplicates
-
JDK-8040892 Incorrect message in Exception thrown by Collectors.toMap(Function,Function)
-
- Closed
-