- 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
WTF? That's riduclous - noone could tink of writing that...
Admin
Java developers never cease to amaze me... :P
Admin
I think .NET does something like this when you ask for a stack trace--it'll throw an exception, catch it, and then give you the stack trace.
The tell-tale "first exception thrown" slowdown is what gave it away to us.
The .NET 'as' operator in C# works the same way. It'll try the cast and if it fails, you'll see the slowdown and get null.
Admin
why would someone do this? I call shenanigans! this is a fake WTF!
I was hoping that wtf would post good code for April foolsand then mock anyone that can't see the "problem" =), or maybe code that looks like it doesn't work, but actually does.
Admin
At least it only catches a NullPointerException...
Admin
As a beginner in Java, I have to ask: how does this even compile?
i.doubleValue() returns a double, but if you don't assign it to something, wouldn't this fail to compile? That is, wouldn't you have to write "double j = i.doubleValue" or something?
Admin
Admin
Actually, this used to be the way to pull a stack trace in Java until 1.5 (where the Thread-object was equipped with similar functionality).. although the choice of exception is a bit unorthodox.
I must say though, it is quite an ingenious way to create objects without the use of the new operator...
Admin
Wrong. Please stop talking if you have no clue what you're talking about.
Admin
What's degrading about sending or receiving code in attachments?
Admin
nonsense. Ever since Java 0.0, you've always had the option to simply construct an exception and access its stack trace.
log.logError(new Exception())
has always worked.
Admin
That is, of course, what I meant, using exceptions to get stack traces. I was referring to the null-catch stuff as means of object-construction.
Admin
What's malicious, contains code and usually comes in attachments?
Admin
Oooh! Oooooooh!! I know this one.... Is it pr0n?
Admin
any office document! :P
captcha: pirates (yarr there be bugs!)
Admin
any office document! :P
captcha: pirates (yarr there be bugs!)
Admin
I usually do something like this:
Throwable stack = new Throwable(); System.err.println("Printing the JVM stack:"); stack.printStackTrace(PrintStream out);
[edit]added optional parameter 'PrintStream out', saves you from having to redirect stderr[/edit]
Admin
No-one ever sends me stuff like that... :-(
Admin
Yeah, no freaking kidding. I don't even know where to start, here.
Admin
Admin
Admin
So I hereby nominate "As an aside, please stop sending code in attachments. It's degrading to both of us." as the designated REAL WTF of this article.
Admin
I nominate using mail clients dumb enough to reformat whitespace as the REALLY REAL WTF. Berkeley mail FTW!
Admin
This, in fact, doesn't work. I tried throwing an exception then catching it to get a stack trace. All you get is the current method. Some checking later revealed
Admin
While this isn't the most elegant way of accomplishing the task, it does seem to work as intended, at least.
The problem for the novice Java programmer, one with which I am familiar, having only taken up the language in the last couple of years after toiling in the vineyards of pure ANSI C for about two decades, is that there's just so damned much of it to assimilate at once. My copy of the O'Reilly Java in a Nutshell book for 1.5 (now outdated) is about 1200 pages, most of it description of the various standard packages. The earlier editions were at least 750 pages.
That's an awful lot of material to assimilate, especially while also trying to keep all of the object oriented concepts and semantics of the language itself straight at the same time.
Searching the web may not necessarily be helpful if you don't know the right search terms to use.
Yes, coding something like
is certainly nicely elegant, it isn't precisely intuitively obvious, is it?Admin
No, you are not required to assign the returned value to anything. I think you might if it's returning a primitive (int, boolean, short, etc), but don't quote me on that.
That code won't even produce any warnings since i is intitialized to null, there's nothing that the compiler would see wrong.
Admin
Hey, I was once working at a software that throwed a weard exception indicating a error at Apache's Log4j... After a full day inpecting the error I found the following code:
Of course that was on a library, with no source code available. So I had to reverse engeneer it...
And didn't have permission to fix either. So I fixed the environment, now the software can open the file, but the bug is still there... Quietly waiting for the next unluck developer...
Admin
Gimme your e-mail adress and I'll make sure you get lots!
Admin
And no you do not need to use the return value of a method call. I can not think of a single language that requires that. Here is a tip: if you have to write "I'm not sure" when discussing basic language features then you probably should not reply at all.
Admin
Ahem, I would like to offer a more enterprisey version:
Admin
There is a huge difference between opening a TXT file and opening an EXE file. And, since one does not know what sort of funky things the recipient's mail client will do to the code if sent in the body of the email, such as reformatting or attempting to compile, it should be standard practice to send code as an attached TXT file.
Admin
Wow. WOW.
That is so much better than even today's hoo-hah.
And regarding the attachment fracas, how about you whiners send your e-mails as PLAIN TEXT?
captcha=stinky ; no comment needed
Admin
BTW searchstrings like: "How to <insert task here> in java" often work surprisingly well.
Admin
Thread.getStackTrace() could be helpful here
Admin
It seems a lot more likely the attachment included surrounding code that was even more embarrassing.
Admin
Admin
@ 2007-04-04 09:08 • by Benanov The .NET 'as' operator in C# works the same way. It'll try the cast and if it fails, you'll see the slowdown and get null.
Try the Environment.StackTrace variable..
Admin
Let me make your life a metric buttload better: http://www.gotapi.com/
I went there imagining I knew nothing about how to produce a stack trace in Java. I clicked J2SE 1.5.0 to pull up the Java documentation, and typed "stack". The result was about a dozen matches. I looked through and found three called "printStackTrace". Two were under java.xml, so obviously not what I wanted. I clicked on the third, and got documentation and examples for how to print a stack trace to standard output, to a PrintWriter, and to a PrintStream.
O'Reilly also used to sell a Java Enterprise CD Bookshelf which had searchable versions of their core Java books. I don't think it has been updated in a while, though; they want you to subscribe to their Safari service instead.
Admin
I'm quite sure there has to be at least one AV prog that will catch source code as well as binaries. After all, source code may as well be some scripted language just waiting for the stupid, eerrr, unsuspecting user to run it.
And since most AV progs hold the users that should not be's hands, well...
Admin
Years (ok, decades) ago, I was working on a system that had been ported from Fortran to C. I had just come from a FORTRAN-G environment, so I hated Fortran with a passion, and I made it my side-task to hunt down and kill every piece of Fortran left in the system. The hardest one of them to replace was called whenever the programmer wanted to print out a VMS stack-trace, which he did by calling this Fortran subroutine that divided by zero, because math in Fortran was exception checked but wasn't in C.
I spend a day hunting through the Orange Wall of VMS system documentation, and finally found a function I could call in C that would emit a VMS stack-trace, and declared the war on Fortran over.
Admin
Admin
Unless, of course, your task is "hook up a hose to a kitchen sink".
Admin
And it's not giving you all the additional information of the original snippet...
Admin
since one does not know what sort of funky things the recipient's mail client will do to the code if sent in the body of the email, such as reformatting or attempting to compile, it should be standard practice to send code as an attached TXT file.
It would be a WTF indeed for a mail client to do anything to a plaintext message body except display it as plain text. Seriously: "attempting to compile"???
If you were to make an argument that attachments are better because they help distinguish between the code sample and the submitter's own commentary thereupon, though, I'd agree with you...
Admin
Admin
For me: it degrades my triage and processing speeds.
For you: your submission is being degraded to an F.
Admin
hahahahaa i lol'ed
Admin
Wirthian Pascal does that. Surprisingly, Borland compilers abolished this 'feature' rather quickly.
Admin
Admin
I did. I enlightened him by telling him that he is completely, utterly, 100% wrong. He postulated that getting a stack trace and using the 'as' operator threw exceptions under the hood when used. They don't. That's all there is to it.
I have very little tolerance or patience for people who spread bad and just plain wrong information using an authoritative tone. He said "The .NET 'as' operator in C# works the same way. It'll try the cast and if it fails, you'll see the slowdown and get null.", as if he knew exactly what happens, when in fact nothing of the sort ever happens. If he's such an authority on things, he should be able to take the effort to re-educate himself on why he's completely and utterly 100% wrong.
QED.