‘this’ can’t be null

dead_fish1.jpg

 

This is the first entry on a category I’d like to name “Code bloopers”. I recently got a message about a piece of code that was throwing a null pointer, it was basically of this form:

synchronized(this.foobar)

This is an easy one. If you think it’s because thisis null, you have to go back to programming 101 and don’t collect $200 if you pass Go. I don’t want to sound mean, but yes, this is one of those bloopers that if you get it wrong, I hope it’s because you are half asleep or on drugs.

Remember kids, this can’t be null. In case you have been a victim of this code blooper, don’t feel bad, you are not the only one confused by this. It’s the only case (that I could find in the internet) of somebody else thinking this can be null, and I hope that gives you some comfort.

Leave a Reply