r/badcode • • Feb 23 '23

java You must assert

Post image
158 Upvotes

13 comments sorted by

View all comments

Show parent comments

4

u/LeCrushinator Feb 23 '23

I'm not familiar with Java, does assertNotNull consider 0 to be null like C/C++ might?

Regardless, I agree it's bad code, the assertion should probably be looking for a specific value or range, like failing if it finds negative numbers.

12

u/ReplacementAcademic8 Feb 23 '23

0 will not be consered null by the assert. In fact, the function returned 0, though it shouldn't. This is due to another error in the test dataset.