Duplicate Key - misleading exception information? [duplicate]
This question already has an answer here:
Why does Collectors.toMap report value instead of key on Duplicate Key error?
4 answers
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
(...)
java java-8 java-stream
marked as duplicate by nullpointer
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why does Collectors.toMap report value instead of key on Duplicate Key error?
4 answers
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
(...)
java java-8 java-stream
marked as duplicate by nullpointer
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Interesting indeed
– ernest_k
Nov 22 '18 at 11:55
1
Probably a bug that was fixed in later versions. When I run this code in Java 10, the exception message is"Duplicate key John (attempted merging values 40 and 30)"
– ernest_k
Nov 22 '18 at 12:03
What version did you use?
– Glains
Nov 22 '18 at 12:05
2
@Glains Reproduced it with Java 8.
– ernest_k
Nov 22 '18 at 12:06
3
It was a bug and fixed in JDK 9. See this: bugs.openjdk.java.net/browse/JDK-8173464
– forpas
Nov 22 '18 at 12:07
add a comment |
This question already has an answer here:
Why does Collectors.toMap report value instead of key on Duplicate Key error?
4 answers
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
(...)
java java-8 java-stream
This question already has an answer here:
Why does Collectors.toMap report value instead of key on Duplicate Key error?
4 answers
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
(...)
This question already has an answer here:
Why does Collectors.toMap report value instead of key on Duplicate Key error?
4 answers
java java-8 java-stream
java java-8 java-stream
edited Nov 22 '18 at 13:36
nullpointer
45.9k1198188
45.9k1198188
asked Nov 22 '18 at 11:46
RLMRLM
4841723
4841723
marked as duplicate by nullpointer
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by nullpointer
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 '18 at 13:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
Interesting indeed
– ernest_k
Nov 22 '18 at 11:55
1
Probably a bug that was fixed in later versions. When I run this code in Java 10, the exception message is"Duplicate key John (attempted merging values 40 and 30)"
– ernest_k
Nov 22 '18 at 12:03
What version did you use?
– Glains
Nov 22 '18 at 12:05
2
@Glains Reproduced it with Java 8.
– ernest_k
Nov 22 '18 at 12:06
3
It was a bug and fixed in JDK 9. See this: bugs.openjdk.java.net/browse/JDK-8173464
– forpas
Nov 22 '18 at 12:07
add a comment |
1
Interesting indeed
– ernest_k
Nov 22 '18 at 11:55
1
Probably a bug that was fixed in later versions. When I run this code in Java 10, the exception message is"Duplicate key John (attempted merging values 40 and 30)"
– ernest_k
Nov 22 '18 at 12:03
What version did you use?
– Glains
Nov 22 '18 at 12:05
2
@Glains Reproduced it with Java 8.
– ernest_k
Nov 22 '18 at 12:06
3
It was a bug and fixed in JDK 9. See this: bugs.openjdk.java.net/browse/JDK-8173464
– forpas
Nov 22 '18 at 12:07
1
1
Interesting indeed
– ernest_k
Nov 22 '18 at 11:55
Interesting indeed
– ernest_k
Nov 22 '18 at 11:55
1
1
Probably a bug that was fixed in later versions. When I run this code in Java 10, the exception message is
"Duplicate key John (attempted merging values 40 and 30)"
– ernest_k
Nov 22 '18 at 12:03
Probably a bug that was fixed in later versions. When I run this code in Java 10, the exception message is
"Duplicate key John (attempted merging values 40 and 30)"
– ernest_k
Nov 22 '18 at 12:03
What version did you use?
– Glains
Nov 22 '18 at 12:05
What version did you use?
– Glains
Nov 22 '18 at 12:05
2
2
@Glains Reproduced it with Java 8.
– ernest_k
Nov 22 '18 at 12:06
@Glains Reproduced it with Java 8.
– ernest_k
Nov 22 '18 at 12:06
3
3
It was a bug and fixed in JDK 9. See this: bugs.openjdk.java.net/browse/JDK-8173464
– forpas
Nov 22 '18 at 12:07
It was a bug and fixed in JDK 9. See this: bugs.openjdk.java.net/browse/JDK-8173464
– forpas
Nov 22 '18 at 12:07
add a comment |
1 Answer
1
active
oldest
votes
It has been fixed in JDK 9. Take a look here.
https://bugs.openjdk.java.net/browse/JDK-8173464
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It has been fixed in JDK 9. Take a look here.
https://bugs.openjdk.java.net/browse/JDK-8173464
add a comment |
It has been fixed in JDK 9. Take a look here.
https://bugs.openjdk.java.net/browse/JDK-8173464
add a comment |
It has been fixed in JDK 9. Take a look here.
https://bugs.openjdk.java.net/browse/JDK-8173464
It has been fixed in JDK 9. Take a look here.
https://bugs.openjdk.java.net/browse/JDK-8173464
answered Nov 22 '18 at 12:08
vinay khuranavinay khurana
763
763
add a comment |
add a comment |
1
Interesting indeed
– ernest_k
Nov 22 '18 at 11:55
1
Probably a bug that was fixed in later versions. When I run this code in Java 10, the exception message is
"Duplicate key John (attempted merging values 40 and 30)"
– ernest_k
Nov 22 '18 at 12:03
What version did you use?
– Glains
Nov 22 '18 at 12:05
2
@Glains Reproduced it with Java 8.
– ernest_k
Nov 22 '18 at 12:06
3
It was a bug and fixed in JDK 9. See this: bugs.openjdk.java.net/browse/JDK-8173464
– forpas
Nov 22 '18 at 12:07