In between my post and yours I've confirmed this bug. The code is correct so I can't work out at the moment why this error is occurring. Similar code is used elsewhere with no errors.
My best guess is that it's to do with Guests permissions. I need to consult with a colleague before I can come up with a fix.
Having said all that, it won't stop the forum running correctly, you error log will just fill up a bit when guests try to right click. Other than space in your error log being taken up there should be no further impact.
I'll post a fix just as soon as I'm able.