I received a really nice SO mug as swag for the choose your own swag contest this year. Everything was working fine until this morning. Was there a patch or update or something?

Here's the relevant code snippet:

if (owner.isCoding() && mug.isEmpty())

Here's a screenshot of what I'm seeing:

Empty SO mug with code on a monitor in the background

As I've highlighted with an orange arrow, I am coding recursive fractals using Logo. You can see also that my cup is empty. I believe this satisfies both conditions specified in the code snippet I posted above, and yet my cup remains empty.

I checked the console and there are no errors. What gives?

  • 17
    -1, orange arrows are soulless – ArtOfCode Apr 1 '16 at 13:48
  • 56
    I see the problem. You assumed using Logo was coding. – John Clifford Apr 1 '16 at 13:49
  • 30
    Oh no! Your password is showing! – Oded Apr 1 '16 at 14:01
  • 7
    @Oded Oops! I'll upload a new screenshot. – Kit Z. Fox Apr 1 '16 at 14:04
  • 1
    Oh, also, I'm not sure if it's relevant, but we just switched to Agile methodology, so I'm pair programming. – Kit Z. Fox Apr 1 '16 at 14:15
  • 10
    It's because that if statement should be while loop, otherwise it will not fill up more than once. I really have no idea why it worked until yesterday... – JonasCz - Reinstate Monica Apr 1 '16 at 14:40
  • 1
    Oh, I see that you're still on Windows XP, maybe that's why it's not working ? Try formatting your hard drive and installing SoCoffeMugLinux™ 16, maybe that fixes it :-) – JonasCz - Reinstate Monica Apr 1 '16 at 14:43
  • 5
    I suspect owner.isCoding() is returning false. Please add a alert(owner.isCoding()) to check it's result. – Arulkumar Apr 1 '16 at 15:15
  • 23
    Have you tried turning it off and turning it back on again? – Alex A. Apr 1 '16 at 23:52
  • 5
    I suspect you have a bug in the mug. Have you used a debugger? – Spikatrix Apr 27 '16 at 13:30
  • 2
    I also suspect that 1) Here owner.isCoding(), you aren't the owner. Someone else is (The guy who made/designed the mug) 2) mug.isEmpty() will always return false as the mug is never empty, it is filled with air. – Spikatrix Apr 27 '16 at 13:33
  • You aren't coding, you are holding the mug. owner.isCoding() returns false so no wonder it isn't filling. – John Militer Apr 2 '17 at 14:51
  • The password is still in the edit history. Is it possible to remove that, maybe for diamond mods? – Fabian Röling Nov 25 '17 at 19:06
  • 2
    @Fabian Thanks for your concern. It's actually a fake. It was intended for humorous effect. – Kit Z. Fox Nov 25 '17 at 21:44
  • Phew, just saved myself from getting whooshed! – Eleeza the Character Wizard Mar 24 '19 at 20:38

You forgot to hook up dependency injection correctly.

You need one of these:

enter image description here

| improve this answer | |
  • 5
    What framework should we use? I have the same problem. – Patrick Hofman Apr 1 '16 at 14:23
  • 39
    @PatrickHofman Clearly the problem is not enough jQuery. – Gilles 'SO- stop being evil' Apr 1 '16 at 14:44
  • 1
    OK, I tried this, but now I'm getting Reference not set to an instance of an object? – Kit Z. Fox Apr 1 '16 at 17:00
  • 4
    @KitZ.Fox - assuming you are using java-beans, did you roast and grind them as the standard requires? – Oded Apr 1 '16 at 17:57
  • 1
    @Oded I did and appended them to the filter object. Maybe I'm invoking the brew method incorrectly. – Kit Z. Fox Apr 1 '16 at 18:44
  • @KitZ.Fox - you may need to post your grounds on MayYourCupOverfloweth.com to get an answer on that. – Oded Apr 1 '16 at 19:01
  • 6
    Is the proposed dependency RFC 2324 compliant? – SEJPM Apr 1 '16 at 22:15

Classic beginner mistake. The code hasn't been run. So, hold the mug and run ... perhaps to the pantry, where the coffee is.

| improve this answer | |
  • 1
    Ah, bad UX on the design then eh? :) – enderland Apr 1 '16 at 14:25
  • 14
    Run, but don't execute the code, those things are kinda hard to ship. – Tim Post Apr 1 '16 at 14:25
  • 1
    Tim, since [mug] isn't instantiated, which one would fill if you had two of these next to each other? – John Clifford Apr 1 '16 at 14:26
  • 7
    Mug is very much instantiated, OP has it in their hand. And mine even reviews code. – Mathieu Guindon Apr 1 '16 at 14:27
  • Yep, in your case isCoding() is false @Mat'sMug – Patrick Hofman Apr 1 '16 at 14:52

Your computer checked Wikipedia and XKCD and discovered that "half full" and "half empty" mean the same thing. Now if

0.5*full = 0.5*empty


full = empty

So your code made the cup empty, on the assumption that that was the same as making it full.

| improve this answer | |
  • 3
    It's not my code! How do I get it fixed? – Kit Z. Fox Apr 1 '16 at 13:56
  • 5
    @KitZ.Fox Find out who wrote it and ply them with coffee until they fix it. – Rand al'Thor Apr 1 '16 at 13:58
  • 3
    Just not from this mug. – John Clifford Apr 1 '16 at 14:18

Assuming your coffee mug isn't playing an April Fools joke on you . . .

This appears to count as undefined behavior. An official source states that (boldface mine)

While no incidents have been reported, the following scenarios might result in undefined mug behavior:

  • Owner changing, or non-owner use of mug
  • Existential difficulties of owner

I suspect that your existential difficulties have led to your working with Logo. Square fractals are recursive, meaning that any time you try to work with them, you'll get back to somewhere similar to where you started. Therefore, whenever you try to drink coffee and work with them, you'll get back to where you started. . .

Any empty mug.

| improve this answer | |

You are most definitely missing a break statement. That thing won't get filled without a decent break.

Also, the if should be a while, obviously...

while (owner.isCoding() && mug.isEmpty())
| improve this answer | |
  • 2
    ... but if I break; first, won't I exit before the mug gets filled? – Kit Z. Fox Apr 1 '16 at 14:43
  • 2
    No, that is a common mistake. In this case the break doesn't cause an exit. – Patrick Hofman Apr 1 '16 at 14:43
  • 9
    Performing break with a mug might initiate garbage collection though, so you need to look out for that. – Simon Klaver Apr 1 '16 at 15:08
  • Never heard of that before. What runtime version do you have? – Patrick Hofman Apr 1 '16 at 15:09
  • 2 it says. – Simon Klaver Apr 1 '16 at 15:15
  • Are you sure it is a mug then? Never actually saw a mug on that runtime. – Patrick Hofman Apr 1 '16 at 15:16
  • 4
    I couldn't update to for some reason. Apparently it would be fixed in that version. – Simon Klaver Apr 1 '16 at 15:20
  • 1
    @Simon I can't believe I missed your jokes last year. Here's a very late laugh: hahaha. – Kit Z. Fox Apr 3 '17 at 12:20

The && operator shorts the circuits, so owner.isCoding() is called but mug.isEmpty() is not. So if you're coding with Legos and you are the one true owner of the mug, it doesn't matter whether your mug is empty, the code will always be called.

The .fill method doesn't do any checking for .isFull() so in your case it looks like the Stack Overflowed and contents was set to 0. You can see using .contents.toLiters() how much is in mug.

I also recommend refactoring the code to make it more efficient. You can do that by reversing the indentation. I think that worked for Mat's Mug.1

You can find more information about this here.

1citation needed

| improve this answer | |
  • 3
    I hate it when my circuits get shorted. – Doorknob Apr 2 '16 at 0:29
  • 2
    Reversing the indentation? Geez have I been doing it wrong all this time?! – Mathieu Guindon Apr 2 '16 at 23:39
  • Umm... the link wasn't broken. (can't see how any of the links is related, but that's a different matter, lol! :)) – Shadow 10 Years Wizard Apr 11 '16 at 6:03
  • @ShadowWizard My esteemed colleague in moderation runs the site that I originally linked to, but unfortunately he removed the redirect for that particular URL. So I had to adapt accordingly. ¯\_(ツ)_/¯ – Alex A. Apr 11 '16 at 6:09

This line:


Does not state the amount of time it takes for the mug to be filled with coffee, or how it's done.

Put the mug, empty, below your pillow at night, and when you'll wake up, it will be full.

Tooth Fairies got some less known relatives, such as Coffee Fairies.

| improve this answer | |

I've finally found a solution for Mac OS X!

Turned out the OS X flavor of Unix doesn't ship with all the required dependencies. The easiest way to install it is via Homebrew.

$ brew install coffee

Strangely the coffee seems to be mildly alcoholic, must be a homebrew issue.

What we really need is a way to run this from a browser. Maybe I'll try porting it to Coffeescript later.

| improve this answer | |
  • 3
    But Java should be installed automatically the first time you try to drink it. – Barmar Apr 7 '16 at 17:34
  • Also this runs fine on ubuntu. – Pax Vobiscum Nov 6 '17 at 11:50

Perhaps they ignored the linker warning: mug was not correctly instantiated.

At least you didn't suffer a core dump. :)

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .