What is the dumbest mistake you could not find for a long time?

I worked on a project that made a mistake, for some reason an exception was not selected, even if it should have been. In depth, I found this error handling:

try { m.invoke(parentObject, paramObj); } catch (IllegalArgumentException e) { new CaseLibException(e); } catch (IllegalAccessException e) { new CaseLibException(e); } catch (InvocationTargetException e) { new CaseLibException(e); } 

My brain realized that a few exceptions were wrapped in another, so not so bad. But I had to stumble upon this code at least 3 times to see what was missing ...

What is your dumbest mistake you could not find?

+4
source share
23 answers

I fixed a bug when the application crashed every day at 6:12 pm.

It turned out that someone saved the number of seconds since the beginning of the day in a 16-bit int.

+19
source

In C / C ++ (which I learned recently)

 if (x = 0) { ... } 
+11
source

Once I wrote a function to parse a date string into a different format. In it, I had a switch / case statement that analyzes the values ​​of the month, it looked like this:

 case month of: 01: return "Jan"; break; 02: return "Feb"; break; ... etc ... 09: return "Sep"; break; 11: return "Nov"; break; 12: return "Dec"; break; end; 

For some reason, I left October ...

+5
source
 for i = 0 to ( list.Length - 1 ) do begin DoSomething( 1 ); end; 

Try to find it on a bulky monitor with a tiny font at 3 o'clock!;)

+5
source
  I=1 

This single Fortran line just didn't work.

After several hours of fruitless debugging, I swallowed my pride and asked a friend to go through the code with me.

Having come to this line, I said: "Now we are increasing the index."

"A?" he says.

That when I realized that I was reading my intentions:

  I=I+1 

instead of what i wrote.

Remember that the next time you are stuck and cannot understand what is wrong.

Do not let your pride keep you from recruiting a second pair of eyes.

+5
source

Actually not initializing some stack variable next to the start of main. The thing is automatically reset, well, almost always.

+4
source

Most of my stupid mistakes were not real mistakes. They had bad data and my assumptions about this data.

I spent hours trying to find an error in the code where there was not a single one - I was debugging an old piece of code, or I assumed that my test data set was something ... and it was not.

+3
source

Not sure if this was the most stupid, but the most unpleasant one I've ever been to, is where I wrote some access control procedures that were partially dependent on the time of day (so you could write rules like "this can only be accessed on a business day during business hours").

I finished the code and carried out all my tests, and everything worked fine. Then I went home, came the next business day, and did all my tests, and they failed. I could not understand why this happened after the code and all the tests were completely unchanged.

It turned out that daylight saving time had begun, and my code could not handle it.

+3
source

When I was much less experienced with curly language, I somehow wrote something like:

 if (expr); stmt; 

This was on the embedded system, so my debugger and printf were powerless. The sound just sounded bad. I set it to low performance and spent a day or so optimizing it. The back of the envelope calculation would show that performance is not a problem.

From this day forward, I always insert my curly braces. This makes me write in Python, if it is not for the rest of the languages.

+3
source

Once upon a time in my CS high school days I implemented a binary tree in (I think) Turbo Pascal. One of the operations did not correctly handle the pointers and ended up rewriting parts of the code segment (oh, the joys of DOS programming). In any case, this always led to overwriting the entire debugging code that I entered, making IF statements seem false, printed statements did not happen, etc., but all miraculously without failures and made it almost impossible to say what was happening .

In the end, I passed it through the debugger at the assembly level and caught the problem when the instructions started to change in the middle of the function ...

+3
source

Once, when I was doing math related to homework, it took me a couple of hours to understand that I have + somewhere where I need *.

+1
source

I wrote a parser using flex / bison. A feature was the constant optimization of the bend, i.e. Replacing 20 + 2 with 22, however my parser replaced it with 4.

As part of the lexer, I had a character table. I used linear search with strncpy to search for existing records. However, for the length parameter in strncpy, I used strlen in the string in the character table. Not a smart idea, because if the entry in the symbol table is smaller, then the one added will incorrectly match. For example, adding “20” would match “2” because only the first character is compared. Therefore, when my parser raised the "20" symbol, it received a "2". I took a watch to understand why my 20 years are changing for 2 s.

+1
source

This is not my fault, but I attended for her. My wife and I took a java class together when we were in college. She's in anthropology, and I'm in finance, but for some reason we ended up in Java. I like it.

She spent the whole evening trying to make a “damned program”, draw a stupid $% ^ & * (house on the screen) and simply could not. Stubborn, she resisted any of my help until her last moment of despair (2, 3 am?). I glanced quickly and noticed that she used “O” (letter o) instead of “0” (zero) throughout.

She left class the next day.

Personally, I have a few stupid mistakes that can be common. My favorites:

dollar sign + function_name using the same iterator ($ i) instead of already loop cycle i ierate random loop "" that happened SOMEWHERE because my hand slipped

+1
source

Also, how can we forget the errors introduced by the evil COPY AND PASTE !!

+1
source

I once debugged a program that was multithreaded, but where multithreading could be turned off. The program will segfault randomly, but only with multithreading support. After trying to isolate each race condition, I realized that the only problem was what I wrote abroad. In single-threaded mode, the memory allocator allocated memory predictably, so that the data at the address located directly above this array is no longer needed by the time it was overwritten, so the error showed no signs. In multithreaded mode, the data at these addresses was data belonging to other streams.

+1
source

Not my worst but recent example of a trawl evil operator:

For a while I was at a dead end why columnCSV was always empty:

 foreach(Column column in Table.Columns) { columnsCSV += string.IsNullOrEmpty(columnsCSV) ? "" : "," + column.Name; } 

Must be

 foreach(Column column in Table.Columns) { columnsCSV += (string.IsNullOrEmpty(columnsCSV) ? "" : ",") + column.Name; } 

PS Please ignore the "lack of StringBuilder".

+1
source

In the old days, when we had a code on cards, I worked for three days trying to understand why my party tasks did not work. I finally got to PRINT messages about every three lines, and I did not see ANY of them.

Then I realized that there was a JCL error that caused my program to load into the corresponding data set (I think it "didn’t get in the way"), so I ran the same old image again and again, instead of the recently compiled one.

+1
source

How is this for a mistake that will make you go crazy trying to figure out what is going on:

 #if CONFIG_SETTING == 1 #define SOME_MACRO( x) doSomething( x); #else #define SOME_MAcRO( x) // don't do it in retail #endif void foo( int a, int b) { if (a < b) SOME_MACRO( a); alwaysCallThisFcn(); // ... } 

So, if CONFIG_SETTING is 1, foo () compiles as:

 void foo( int a, int b) { if (a < b) doSomething( a);; // note: the second // semi-colon has no effect alwaysCallThisFcn(); // ... } 

Otherwise, it is compiled as:

 void foo( int a, int b) { if (a < b) alwaysCallThisFcn(); // now alwaysCallThisFcn() is // called conditionally // ... } 
+1
source

Why, I never made a mistake in my life!

0
source

I can’t tell you the specific error that I encountered, but I can say that you have involved at least one of the following:

  • Something is supposed to work
  • Data Assumption
  • Typo
  • A = instead of ==
  • Something I would need to reorganize

Actually, a list of the causes of all my mistakes;)

0
source

} and sometimes)

0
source

The most stupid mistake:

  if(a=!0) 

instead:

  if(a!=0) 

It took me 4 hours to identify the problem as the compiler was just going crazy! I almost died when I found out!

0
source

This is one of my early silly mistakes.

We have an existing project for work where there is WebMethod written in C #

 switch (option) { case "one" : //ToDos break; case "two" : //ToDos break; case "three" : //ToDos break; } 

While from clientCode (via ajax) we got the following as an option

 One Two Three 

I could not understand where the problem was, after 30-40 minutes.

I fixed it as

  switch (option.ToLower()) { 
0
source

All Articles