Suppose you find yourself in the following situation:
You have a good relationship with your direct boss, and you are a subject expert in the field. The boss is telling you to do something (a technical decision), but you feel very strongly that it is a bad idea and will hurt both of you in the long term. You suspect he has been out of touch with code for a while, doing managerial things, and is not making the best decision. You suspect he is shooting himself in the foot but you're just unable to convince him of that (discussions have deadlocked). If the whole thing doesn't work later there will be repercussions for the entire team.
So the choice is to either always do what you're told, or quietly do what you think is right.
On one hand, doing the former will make sure that no blame falls on you if things go south, and if (when) it does, you will have the "I told you so" rights. On the other hand, I really don't want this guy to get screwed, and I don't want the team to spend weekends fixing production problems. This guy is a good guy, but he's not a developer anymore and he is having a hard time letting go. What's the right way to handle this?
Thanks everyone for replies, they seem more or less unanimous. I will follow your advice.
For the record, my difficulty was in the fact that we are on very friendly terms (outside of work too) with my boss. It's more than just a pure work relationship, and that is convoluding things. Shouldn't matter though - thanks everyone.