Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
1. Introduction
Still remember that day, the new test little sister came to me and said: “handsome boy, your code is wrong!” I hurriedly explain: “little elder sister rice can disorderly eat, words can’t talk nonsense oh, how do you know this Bug is I write?”
What happened is that one day when I was reviewing the intern code, I found that the collection shorting was not done properly. So I changed his code with three parts casual, two parts sigh, five parts education mood, because the code is too simple and then submitted and left behind
The result code to test the little sister’s hand, there is the beginning of the sentence hello……
Bug or not, I just love hearing people call me handsome
2. The event
One day in 2021, the weather is fine, the mood is cloudy
During Review, I found that the intern guy wrote such a code
List<Object> list;
// Business logic......
if(list.size() ! =0) {
// Business logic
}
Copy the code
I think his intention is to operate on the data when the set is not empty, so I’m going to change it to that because of the wavy line
List<Object> list = null;
// Business logic......
if (list.isEmpty()) {
// Business logic
}
Copy the code
Obviously I forgot to invert, which directly caused one of the get() operations on the next line to throw an out-of-bounds array exception
Old face can not hold my face immediately in front of the test little sister, earnest of the internship boy said: “you this, the code, a little problem; I, help you change good, your next rat-tail juice, don’t be careless!”
The young man hurriedly nods to say is, I two pair of look knowing smile, he understood, I also understood!
Later, I realized that when I went to the bathroom, the intern told my sister that I had corrected the Bug…
3. Some thinking
In fact, it is not uncommon for programmers to be careless in code, and even more careless to execute rm -f * wrong directory
At the end of the day, in addition to your own code should be more careful, but also to develop good development habits, strictly abide by the development specifications, especially in the early stage of writing code, this is the best time for you to develop good development habits, good code style, after this stage is really difficult to correct
Sentenced to empty the collection problems, for example, we can through the habit to avoid such problems, like now, I’ll use Hutool CollectionUtil isEmpty (), CollectionUtil. IsNotEmpty () to empty the collection, This is the best way to avoid the careless problems mentioned above
4. Write at the end
Thank you for reading, I am Java chicken development, if I write the content can make you feel helpful, but also hope not hesitate to like, pay attention to, collect, of course, if can forward better
If you want to learn more, please visit my personal blog: Javaš¤ chicken development de blog