You cite examples where the law forbids something, but a judicial opinion allows it. So one easy way to avoid doing something illegal in all of your examples is to simply follow the law as written.
Sure, maybe with legal counsel you could push things a little further, get your nunchuck possession charge dismissed because you were pulled over two hundred yards past the Yuba county line or whatever, but that's different from someone who wants to avoid getting in trouble in the first place.