Duplicate Key - misleading exception information? [duplicate]












6
















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
(...)









share|improve this question















marked as duplicate by nullpointer java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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
















6
















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
(...)









share|improve this question















marked as duplicate by nullpointer java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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














6












6








6









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
(...)









share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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 java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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














  • 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












1 Answer
1






active

oldest

votes


















5














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






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














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






    share|improve this answer




























      5














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






      share|improve this answer


























        5












        5








        5







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






        share|improve this answer













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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 12:08









        vinay khuranavinay khurana

        763




        763















            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python