• Bob (unregistered)

    WTF? That's riduclous - noone could tink of writing that...

  • (cs)

    Java developers never cease to amaze me... :P

  • (cs)

    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.

  • ethan (unregistered)

    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.

  • (cs)

    At least it only catches a NullPointerException...

  • JavaNoob (unregistered)

    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?

  • (cs) in reply to JavaNoob
    JavaNoob:
    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?

    It's not required to use return values in Java. I don't even think you'll get a compiler warning in this situation. At least I don't remember ever seeing such a warning.

  • (cs)

    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...

  • RON (unregistered) in reply to Benanov
    Benanov:
    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.

    Wrong. Please stop talking if you have no clue what you're talking about.

  • Sgt. Preston (unregistered)

    What's degrading about sending or receiving code in attachments?

  • David Hall (unregistered) in reply to roe

    this used to be the way to pull a stack trace in Java until 1.5

    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.

  • (cs) in reply to David Hall
    David Hall:
    >> this used to be the way to pull a stack trace in Java until 1.5

    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.

    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.

  • Bob (unregistered) in reply to Sgt. Preston
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

  • diaphanein (unregistered) in reply to Bob
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    Oooh! Oooooooh!! I know this one.... Is it pr0n?

  • Chris (unregistered) in reply to Bob

    any office document! :P

    captcha: pirates (yarr there be bugs!)

  • Chris (unregistered) in reply to Bob
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    any office document! :P

    captcha: pirates (yarr there be bugs!)

  • (cs)

    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]

  • Bob (unregistered) in reply to diaphanein
    diaphanein:
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    Oooh! Oooooooh!! I know this one.... Is it pr0n?

    No-one ever sends me stuff like that... :-(

  • Mystified (unregistered) in reply to RON
    RON:
    Benanov:
    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.

    Wrong. Please stop talking if you have no clue what you're talking about.

    Yeah, no freaking kidding. I don't even know where to start, here.

  • Sgt. Preston (unregistered) in reply to Bob
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    That might make the practice inconvenient, but how is it "degrading"?

  • (cs) in reply to diaphanein
    diaphanein:
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    Oooh! Oooooooh!! I know this one.... Is it pr0n?

    He said "malicious", not "delicious"!

  • (cs) in reply to Bob
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    Executable code. Source code, however, is completely harmless, and it's generally a Really Good Idea to send code as an attachment since e-mail clients are notorious for screwing up formatting.

    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.

  • Bearded Unix Guru (unregistered) in reply to Zylon
    Zylon:
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    Executable code. Source code, however, is completely harmless, and it's generally a Really Good Idea to send code as an attachment since e-mail clients are notorious for screwing up formatting.

    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.

    I nominate using mail clients dumb enough to reformat whitespace as the REALLY REAL WTF. Berkeley mail FTW!

  • (cs) in reply to Benanov
    Benanov:
    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.

    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

    1. A perfectly good method in diagnostics to get a stack trace from
    2. That the docs do tell you that the exception stack trace only contains the amount of the stack that has been unwound while finding a catch block.
  • Steve (unregistered)

    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

    new Throwable().printStackTrace();
    is certainly nicely elegant, it isn't precisely intuitively obvious, is it?
  • (cs) in reply to JavaNoob
    JavaNoob:
    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?

    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.

  • (cs)

    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:

    Logger l = null;
    try{
       l = new Logger("FileName");
    }catch(Exception e){
       l.log(e);
    }
    

    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...

  • FredDC (unregistered) in reply to Bob

    Gimme your e-mail adress and I'll make sure you get lots!

  • Asd (unregistered) in reply to Mcoder
    Mcoder:
    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:
    Logger l = null;
    try{
       l = new Logger("FileName");
    }catch(Exception e){
       l.log(e);
    }
    
    Absolutely brillant. You should have submitted that.

    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.

  • (cs) in reply to Steve

    Ahem, I would like to offer a more enterprisey version:

       import java.io.*;
       import javax.xml.parsers.*;
       import javax.xml.xpath.*;
    
       try {
           String                 xml      = "<doc ...> ... </doc>";
           String                 xpathExp = null;
           byte                   bytes[]  = xml.getBytes();
           ByteArrayInputStream   bais     = new ByteArrayInputStream(bytes);
           DocumentBuilderFactory dbf      = DocumentBuilderFactory.newInstance();
           DocumentBuilder        builder  = dbf.newDocumentBuilder();
           Document               doc      = builder.parse(bais);
           XPath                  xpath    = XPathFactory.newInstance().newXPath();
    
           String                 data     = (String) xpath.evaluate(
                                                 xpathExp, 
                                                 doc,
                                                 XPathConstants.STRING);
       // Catch all of:
       //   XPathExpressionException
       //   ParserConfigurationException
       //   SAXException
       //   IOException
       //   Exception
       } catch (Throwable wtf) {
         wtf.printStackTrace(PrintStream out);
       }
    
  • Ed (unregistered) in reply to Bob
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    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.

  • DSTMan (unregistered) in reply to Asd
    Asd:
    Mcoder:
    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:
    Logger l = null;
    try{
       l = new Logger("FileName");
    }catch(Exception e){
       l.log(e);
    }
    
    Absolutely brillant. You should have submitted that.

    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.

    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

  • (cs) in reply to Steve
    Steve:
    ... Yes, coding something like
    new Throwable().printStackTrace();
    is certainly nicely elegant, it isn't precisely intuitively obvious, is it?
    I agree 100%. Java just is not the most intuitive, compact or pragmatic language in the world. And after 2 years, I still regularly use Google(codesearch) when programming in Java.

    BTW searchstrings like: "How to <insert task here> in java" often work surprisingly well.

  • Bavo (unregistered)

    Thread.getStackTrace() could be helpful here

  • Scott Robinson (unregistered)

    It seems a lot more likely the attachment included surrounding code that was even more embarrassing.

  • Ohnonymous (unregistered) in reply to Zylon
    Zylon:
    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.
    Second.
  • Lodo (unregistered)

    @ 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..

  • mathew (unregistered) in reply to Steve
    Steve:
    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.

    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.

  • cognac (unregistered) in reply to Ed
    Ed:
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    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.

    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...

  • (cs)

    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.

  • NOR (unregistered) in reply to RON
    RON:
    Benanov:
    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.

    Wrong. Please stop talking if you have no clue what you're talking about.

    Please stop talking if you have no intention to enlight the unenlightened.

  • (cs) in reply to Gyske
    Gyske:
    Steve:
    ... Yes, coding something like
    new Throwable().printStackTrace();
    is certainly nicely elegant, it isn't precisely intuitively obvious, is it?
    I agree 100%. Java just is not the most intuitive, compact or pragmatic language in the world. And after 2 years, I still regularly use Google(codesearch) when programming in Java.

    BTW searchstrings like: "How to <insert task here> in java" often work surprisingly well.

    Unless, of course, your task is "hook up a hose to a kitchen sink".

  • (cs) in reply to Steve
    Steve:
    Yes, coding something like
    new Throwable().printStackTrace();
    is certainly nicely elegant, it isn't precisely intuitively obvious, is it?

    And it's not giving you all the additional information of the original snippet...

  • (cs) in reply to Ed

    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...

  • (cs) in reply to mathew
    mathew:
    Steve:
    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.

    Let me make your life a metric buttload better: http://www.gotapi.com/

    I've just fallen in love...
  • (cs) in reply to Sgt. Preston
    Sgt. Preston:
    That might make the practice inconvenient, but how is it "degrading"?

    For me: it degrades my triage and processing speeds.

    For you: your submission is being degraded to an F.

  • (cs) in reply to diaphanein
    diaphanein:
    Bob:
    Sgt. Preston:
    What's degrading about sending or receiving code in attachments?

    What's malicious, contains code and usually comes in attachments?

    Oooh! Oooooooh!! I know this one.... Is it pr0n?

    hahahahaa i lol'ed

  • Anonymous (unregistered) in reply to Asd
    Asd:
    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.

    Wirthian Pascal does that. Surprisingly, Borland compilers abolished this 'feature' rather quickly.

  • (cs) in reply to Gyske
    Gyske:
    mathew:
    Let me make your life a metric buttload better: http://www.gotapi.com/
    I've just fallen in love...
    You and me both. I've bookmarked gotapi on del.icio.us and I'm making http://start.gotapi.com/ my startpage. Thank you, mathew. I've been looking for a site like gotapi for a long time.
  • RON (unregistered) in reply to NOR
    NOR:
    RON:
    Benanov:
    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.

    Wrong. Please stop talking if you have no clue what you're talking about.

    Please stop talking if you have no intention to enlight the unenlightened.

    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.

Leave a comment on “Bringing LOGing Back”

Log In or post as a guest

Replying to comment #130210:

« Return to Article