• (nodebb)

    TRWTF is that this wasn't caught by tests - he does have tests, right?

  • P (unregistered) in reply to Peter Street

    What, someone actually write automated tests for mobile apps? Now that's TRTRWTF there.

  • Hans (unregistered)

    Unfortunately it is not specific to Java - C# acts the same way, for the same reason (with a compiler warning about unused references)

  • Jonathan (unregistered)

    I just tested this to be sure, but in C# and the label doesn't change the flow of code at all, it just steps over it, I would expect Java to be the same. It would only make difference if somewhere there was a "goto http".

  • (nodebb) in reply to Hans

    Unfortunately it is not specific to Java - C# acts the same way, for the same reason (with a compiler warning about unused references)

    Pedantic C89/90/ANSI C doesn't have this particular problem because it doesn't have slashslash comments, but C++ and C99 can do it easily.

    Or you can construct a switch that doesn't work correctly, using a small typo (except that "défaut" is French for "default"...):

    switch (expression)
    {
        case FIRST_THING:
        // normal stuff
        //...
            break;
    
        defaut:
            // unreachable stuff
    }
    

    If you're lucky, you get a warning about the unused label and/or the unreachable code.

  • thunderbird (unregistered)

    There's something off about this: on a hunch, I pasted the code into a Java scratch in IntelliJ, and the URL line is marked as a compilation error ("Label without statement"), so this shouldn't even have built. My hunch was that since Java doesn't ACTUALLY support labels, the label itself would be marked as an error, but that's not the case. Though goto IS marked as unexpected token.

  • (nodebb)

    Morale of the story: always paste URLs on an empty line.

  • Jaloopa (unregistered) in reply to Jonathan

    I just tested this to be sure, but in C# and the label doesn't change the flow of code at all, it just steps over it, I would expect Java to be the same. It would only make difference if somewhere there was a "goto http".

    Or if the url was pasted in before an actual statement, thus commenting it out. If someone did something like that it would be quite the WTF and be worthy of posting on a site that has one every day

  • (nodebb) in reply to thunderbird

    the URL line is marked as a compilation error ("Label without statement")

    It shouldn't be, because in the original, there is a statement after the label: Log.d("toast", msg);

    Well, unless Java has some wanked rule about the statement that follows a label having to begin on the same line as the label, which should be, well, just wrong.

  • Wayne (unregistered)

    This will date me a bit. I once thanks to the wonder that is Vi, randomly pasted an entire COBOL file into the middle of itself, by typing in command mode instead of line edit mode This resulted in compiler error messages that no one could decipher. The issue was found by doing a diff with the original version

  • WTFGuy (unregistered)

    @Peter Street: But a unit test won't detect this goof. You need a UI-level testing harness that can validate that the toast actually appears on the display. IANA Android dev, but are such harnesses available?

  • Svempa (unregistered)

    The only WTF here is why the submitter didn't imediately check the commit log and use diff. Sure it's a fun corner case that the code actually compiled, but version control eats unit tests for breakfast.

  • Smithers (unregistered) in reply to thunderbird

    I think the Java language spec. permits this label (as there is a statement following it) although it is useless, so IntelliJ may be flagging it for that. Even if it is against the JLS, I don't know how strictly accurate the Android compiler is.

    Java does actually have labels, what it doesn't have is goto, so their only purpose is when the labelled statement is a loop for use with labelled breaks and continues.

  • Conradus (unregistered)

    And that, students, is why your standards need to include a requirement that everything has to compile cleanly with no warnings before it's checked in. Being required to address an "unused label" warning would've solved this whole problem.

  • Naomi (unregistered) in reply to thunderbird

    You are allowed to label any statement in Java, but the only way they are used is as a target of a (labeled) break or continue statement. [https://stackoverflow.com/a/16555473[(https://stackoverflow.com/a/16555473)

  • Naomi (unregistered) in reply to Naomi

    TRWTF is TDWFT's lack of a preview feature!

  • markm (unregistered)

    Could someone please explain how inserting a label, with no statement referring to it, would silently change the behavior of Java code?

    In c++ or in any c compiler that recognizes '//' as a comment, this would have no effect except possibly a warning about the unused label. In a very old c compiler, it would attempt to parse the part after ':', fail, and not generate an executable, but in no language I've ever learned would a label cause a jump out of the code.

  • Just Me (unregistered) in reply to markm

    The code to actually display the popup is commented out because it's on the same line as the URL.

  • Anonymous (unregistered) in reply to Peter Street

    A few years ago, they made it impossible to test toast messages. By "impossible", I mean the accepted answer on Stack Overflow stopped working. Now, the only known way to test toasts is via pixel-perfect screenshot validation

  • (nodebb) in reply to WTFGuy

    If your unit test framework mocks out UI code and replaces it with code that tests to make sure expected calls happen it can very easily detect this goof. It just happens that there are java utilities for exactly this purpose.

  • Martin Tilsted (unregistered) in reply to markm

    The reason this prevented the toast, is that http: becomes a label, and then the rest of the line, including the call to show() becomes a comment, due to the //. (If there had been a newline after the paste, nothing would have been broken).

  • Sole Purpose of Visit (unregistered)

    There's no real WTF here. It amounts to misinterpreting a single line of syntax in a common language, which I've got to admit I do every other day (with or without copypasta). Stare at the screen, wonder what could possibly be the problem, mutter imprecations, and sit back, drink a couple a sips a coffee, and slap forehead.

    If you're expressing a badly-defined idea in a syntactically correct way, then this is the utterly mundane outcome.

    Four decades after "Goto considered harmful," however, it would be nice if modern brackety languages would either (a) ban the damn thing (I do not hold out hope) or (b) flag any label whatsoever as a compiler warning.

    (I do not hold out hope for that, either.)

  • Sole Purpose of Visit (unregistered)

    Fifty two years, excuse me.

    Not much when set against human evolution, but considering that it was flagged up by Dijsktra a mere 32 years after Turing's computability paper ... well, that's a sizeable proportion of computer science history that has clearly lost the plot in this particular case.

  • Sole Purpose of Visit (unregistered)

    I blame Algol68 myself.

    It was probably the first exhaustively defined language, and arguably the predecessor of all modern procedural languages. And, of course, as one would expect of the times, it had the goto keyword.

    But as far as I'm aware, it didn't have labels. You could basically only "go to stop", which was the equivalent of "return".

    If I'm correct in this assumption, it's a tragedy. No labels === goodiness. Leaving goto inside the syntactic definition ... well, the nearest thing to the human appendix I can imagine. With the caveat that the human appendix might actually still be useful.

    Of course, in the case under present discussion, we have an accidental label without the concomitant appendix.

  • Andreal (unregistered)

    Labels are part of the java language:

    https://www.decodejava.com/java-labelled-break.htm

  • Tim Berners Lee’s conscience (unregistered)

    Another victim of the unnecessary // in URL…

  • Loko8765 (unregistered)

    Code review, people, peer code review. AND automated tests.

  • Peter Wolff (unregistered) in reply to Tim Berners Lee’s conscience
    Comment held for moderation.
  • Richard Wells (unregistered) in reply to Sole Purpose of Visit

    I can actually think of two arguably legitimate uses of "goto":

    (1) Error handling in C. It can help avoid deeply nested code. (2) Finite state machines. See Elements of Programming by Stepanov and McJones for a good example.

Leave a comment on “Accidental Toast of the Town”

Log In or post as a guest

Replying to comment #:

« Return to Article