Remember the weird bug debug —————— The difference between the hash (key) algorithm for HashSet in JDK1.7 and JDK1.8

Source: Internet
Author: User

Phenomenon:

The test has a bug that I can't reproduce, but the paradox is that it can be reproduced on other people's machines. Originally thought to be a conflict after SVN merger, and then after the comparison to troubleshoot:

Step 1:

I opened two local jetty, a run before the merger of the version, a run after the merge version, database, Redis configuration is the same, the result is consistent, it can be inferred that it should not be a code problem.

Step 2:

My computer and other computers the same configuration, a database, the same code, the same data, got two results, I am normal here, and in addition to my other people can reproduce, I meow dog ....

I thought it was a supernatural phenomenon ... o (╯-╰) o

Step 3:

For a long time, notice there is still a different place, my local JDK version is 1.8, they include the test server should be 1.7 version.

Later, it was proven that the key point was that, at the front end of the presentation, the previous person wrote a list of the order in which the list was displayed, depending on the order of an unordered data structure set !!!

Because the hash algorithm of JDK7 and JDK8 is different, and the order of the hash above the JDK8 is just right (really funny ...). ), and then there will be a problem before jdk7.

Rethinking the cause of the problem:  

Because this JS file is too difficult to control (maintainability is basically negative, I think there is no need to take the time to understand the bad code, the code jianfengchazhen put in the problem just fine .... )

Let me change other people's code, always resist to understand other people's code (although it is not understood at all ...) ), but let me rewrite a new feature when it feels relatively cool, flowing feeling, logic is also clearer, but as a low-level yards of farmers, to others wipe the buttocks is probably the necessary skills ...

Here also found a very interesting phenomenon, the beginning of the time I carefully write code, and then I found that before the people are so written, and then I do not consciously began to write, anyway, we all do so, probably this is the project development in the broken window effect bar. Once it starts to rot, it's out of hand ....

Solution:

In the future, it is a superficial solution to make version unification with others, and the basic solution is to have a brain when writing code ... A Brain! Child To prevent the force, we have to pick two different time periods review two times.

In order to avoid the later people fall out of the pit, would like to return to the client when the set to sort, but I have not dared to tamper with the code, moved a place elsewhere will be a variety of bugs ..., simply force him to use Linkedhashset forget ...

This problem is a sloppy solution ....

The difference between hash algorithms in JDK1.7 and JDK1.8:

hash algorithm for map 1.7:

hash algorithm for map 1.8:

.

Remember the weird bug debug —————— The difference between the hash (key) algorithm for HashSet in JDK1.7 and JDK1.8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.