- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
TRWTF is that this wasn't caught by tests - he does have tests, right?
Admin
What, someone actually write automated tests for mobile apps? Now that's TRTRWTF there.
Admin
Unfortunately it is not specific to Java - C# acts the same way, for the same reason (with a compiler warning about unused references)
Admin
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".
Admin
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"...):
If you're lucky, you get a warning about the unused label and/or the unreachable code.
Admin
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.Admin
Morale of the story: always paste URLs on an empty line.
Admin
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
Admin
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.
Admin
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
Admin
@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?
Admin
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.
Admin
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.
Admin
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.
Admin
Admin
TRWTF is TDWFT's lack of a preview feature!
Admin
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.
Admin
The code to actually display the popup is commented out because it's on the same line as the URL.
Admin
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
Admin
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.
Admin
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).
Admin
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.)
Admin
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.
Admin
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.
Admin
Labels are part of the java language:
https://www.decodejava.com/java-labelled-break.htm
Admin
Another victim of the unnecessary // in URL…
Admin
Code review, people, peer code review. AND automated tests.
Admin
[/quote] Another victim of the unnecessary // in URL… [/quote]
Actually, afaik a single slash is/was to go back to the root level of the local file system, and a double slash is/was to go up to the level above the servers. (An address without a slash should start in the current directory of the environment.)
Admin
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.
Admin
"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."
I'm not sure there are Android utilities for such. You can write a test that runs the app and clicks on things and tests what the UI does, but someone else said there's no good way to test that toast messages appear. As far as I know the Android platform offers no hooks to verify that Toast.show() gets called, which leaves you with taking a screen shot and testing it against a reference image. Obviously this is both disgusting and not a unit test.
Admin
Be On The Lookout For: How Ticktok Pornstars Is Taking Over And How To Respond Tiktok Pornstar (Minecraftathome.Com)