Java SQL interface exception



  • I was writing a bit of database interface code and forgot that java.sql.ResultSet indexes columns from 1, rather than 0 (like almost everything else in computer science). The exception I got was interesting:

     wtf1

     

     

    Something was amiss, I checked my maths book "Assertions for dummies" and I was correct!

    "0 > 2" == false

    I thought I'd try something else and tried to get the "-1th" column, and lo and behold:

    wtf2 

     

     

    It seems that when you have a valid range of integers, providing an integer greater than this range is the only possible misuse!



  • So the writers of that code checked for both ends of the range, but used the same message (written for the upper end) for both cases.

    Yes, its a bug.

    Yes, the wrong error message looks really funny.

    No, I don't consider this a big deal.



  • ...and unlike what the OP suggests, it's really "only" com.mysql.jdbc.ResultSet that's bugged, java.sql.ResultSet is an interface and contains no code.

    Additionally, the latest version of the connector already has this changed to use two different messages.



  • @TheRider said:

    So the writers of that code checked for both ends of the range, but used the same message (written for the upper end) for both cases.

    Yes, its a bug.

    Yes, the wrong error message looks really funny.

    No, I don't consider this a big deal.

    Sorry, I'll pass them all by you next time.



  • @Pidgeot said:

    ...and unlike what the OP suggests, it's really "only" com.mysql.jdbc.ResultSet that's bugged, java.sql.ResultSet is an interface and contains no code.

    Additionally, the latest version of the connector already has this changed to use two different messages.

    I never said the interface contains code, all I said is that the interface indicates that the indexing starts at 1, which it does (http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getString(int)). Why do some people on these boards have to be so pedantic and try to find fault with ANYTHING that people say? Even to the point of trying to twist what you say just to 'get one up' on other people?



  • @slyadams said:

    I never said the interface contains code, all I said is that the interface indicates that the indexing starts at 1, which it does (http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getString(int)). Why do some people on these boards have to be so pedantic and try to find fault with ANYTHING that people say? Even to the point of trying to twist what you say just to 'get one up' on other people?
     

    I think harping on others' missteps, no matter how small, is the entire point of this website, isn't it? You probably shouldn't take it personally; it's just what we do. Heck, take a look at your OP: the issue's already been fixed in the latest version of the software in question.

    Still, I think your OP was a fairly well-written presentation for the bug in question ("Assertions for Dummies", heh), so I still found it amusing. That's just me, though. ._.



  • Your post suggested to me that your intended "target" was the exception message, not the practice of numbering from 1. However, since you didn't mention any part of the MySQL connector explicitly (no, I don't count the stack traces, because they don't show anything about YOUR awareness), but DO mention java.sql.ResultSet by full name, that leads me to believe you are not concerned with the fact that this is code from a specific implementing class.

    On this board, it can occasionally be hard to tell the difference between people that leave out certain things on purpose, and people that just don't know what they're talking about, so many people have a tendency to call each other out on such things if there's room for doubt.



  • @Pidgeot said:

    Your post suggested to me that your intended "target" was the exception message, not the practice of numbering from 1. However, since you didn't mention any part of the MySQL connector explicitly (no, I don't count the stack traces, because they don't show anything about YOUR awareness), but DO mention java.sql.ResultSet by full name, that leads me to believe you are not concerned with the fact that this is code from a specific implementing class.

    On this board, it can occasionally be hard to tell the difference between people that leave out certain things on purpose, and people that just don't know what they're talking about, so many people have a tendency to call each other out on such things if there's room for doubt.

    The only reason I mentioned the interface by name is that it is the interface that imposes the indexing from 1, and that is what caught me out and caused me to find the interesting error message in the first place. I probably should have added where the error message actually 'resides', but, to be honest, I'm at work and didn't even bother to proof read, let alone make sure all my techincal bases were covered! ;-)



  • I'm liking the green letters on black screen.  

    Reminds me of coding in COBOL and the Matrix.



  • @belgariontheking said:

    I'm liking the green letters on black screen.  

    Reminds me of coding in COBOL and the Matrix.

     

    I know right! You gotta do something to make writing perl somewhat tolerable!



  • @slyadams said:

    @belgariontheking said:

    I'm liking the green letters on black screen.

    Reminds me of coding in COBOL and the Matrix.

    I know right! You gotta do something to make writing perl somewhat tolerable!
    Very true.

    Cue someone wondering what's so fun about coding in COBOL ...  



  • I'll tell you what's funny about coding in COBOL, it's what it does to a person. I sat next to this person who had been coding for years and years. Here's how it sounded to me:

     

    mumble mumble mumble dot

    mumble mumble mumble dot

    mumble mumble mumble DOT

    mumble mumble mumble DOT

     

    All. Day. Long. She also abused the hell out of the right hand control key, banging on it repeatedly.



  • @dextron said:

    I'll tell you what's funny about coding in COBOL, it's what it does to a person. I sat next to this person who had been coding for years and years. Here's how it sounded to me:

     

    mumble mumble mumble dot

    mumble mumble mumble dot

    mumble mumble mumble DOT

    mumble mumble mumble DOT

     

    All. Day. Long. She also abused the hell out of the right hand control key, banging on it repeatedly.

     Sounds like she has Swampie's disease.  It's fatal if not treated early.


  • @slyadams said:

    I never said the interface contains code, all I said is that the interface indicates that the indexing starts at 1, which it does (http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getString(int)). Why do some people on these boards have to be so pedantic and try to find fault with ANYTHING that people say? Even to the point of trying to twist what you say just to 'get one up' on other people?

     

    Ok, the faulty error message is quite funny. You are absolutely right.

    The thing is that the error message doesn't have anything to do with the fact that the valid range starts with 1 instead of 0. Even if the valid range started at 0, if you tried -1 or any other negative number, you would still have had the faulty error message that reported a problem with the UPPER end of the range.

    The range starting at 1 doesn't really appear as a WTF to me, because I work with java.sql for many years and have gotten used to it. Besides that, I have met other languages in my developer live that started array with 1 or even arbitrary numbers. Therefore, indexes starting at 0 don't appear sillver bullets for all problems.

    Long story cut short: The WTF boils down to be an implementation bug that apparently has been fixed in a later revision. The index starting at 1 is not, at least not in my eyes.



  • @TheRider said:

    Besides that, I have met other languages in my developer live that started array with 1 or even arbitrary numbers. Therefore, indexes starting at 0 don't appear sillver bullets for all problems.

    I wish there was a way to force all of them to use zero. It's annoying to have to remember which is which. Controls tend to use 1, but data ones (lists, arrays, etc) use zero -- but it's not always this way.



  • @TheRider said:

    @slyadams said:

    I never said the interface contains code, all I said is that the interface indicates that the indexing starts at 1, which it does (http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getString(int)). Why do some people on these boards have to be so pedantic and try to find fault with ANYTHING that people say? Even to the point of trying to twist what you say just to 'get one up' on other people?

     

    Ok, the faulty error message is quite funny. You are absolutely right.

    The thing is that the error message doesn't have anything to do with the fact that the valid range starts with 1 instead of 0. Even if the valid range started at 0, if you tried -1 or any other negative number, you would still have had the faulty error message that reported a problem with the UPPER end of the range.

    The range starting at 1 doesn't really appear as a WTF to me, because I work with java.sql for many years and have gotten used to it. Besides that, I have met other languages in my developer live that started array with 1 or even arbitrary numbers. Therefore, indexes starting at 0 don't appear sillver bullets for all problems.

    Long story cut short: The WTF boils down to be an implementation bug that apparently has been fixed in a later revision. The index starting at 1 is not, at least not in my eyes.

     

    Sigh. The WTF was NEVER the indexing starting at 1. It can start at 3 for all I care. I was merely pointing out that it is somewhat unusual and it was the reason I made the error in the first place that caused the exception to be thrown. I was giving backstory. The WTF is the fact that someone thought that providing an integer greater than a range is the only way to misuse such a range.

    I really am through trying to explain this now.



  • @AbbydonKrafts said:

    I wish there was a way to force all of them to use zero. It's annoying to have to remember which is which. Controls tend to use 1, but data ones (lists, arrays, etc) use zero -- but it's not always this way.

    Yeah, no joke.  I guess if we were starting with a clean slate it might make sense to force everything to start with 1, but 0 has been common for so long.  Perhaps it's just because I use languages mostly derived from C, but why would anyone got out of their way to add confusion by starting with 1? 



  • @slyadams said:

    The WTF is the fact that someone thought that providing an integer greater than a range is the only way to misuse such a range.

    I am very sorry to disagree. No, he didn't. He DID check for both ends of the range. He ONLY forgot to show the correct error message on the lower end of the range.

    @slyadams said:

    I really am through trying to explain this now.

    Yep. Let's give peace a chance :-)

     



  • Replies to posts should be banned in this forum. We should just have posts, no discussions. I wonder how many awesome WTFs are out there not being posted because the potential posters are worried about getting flamed (or at least mugged) by people who are more interested in judging than in laughing...



  • @ThePants999 said:

    Replies to posts should be banned in this forum. We should just have posts, no discussions. I wonder how many awesome WTFs are out there not being posted because the potential posters are worried about getting flamed (or at least mugged) by people who are more interested in judging than in laughing...
     

    Or people who get 'mugged' could stop posting flaming piles of crap.... You know, whatever.



  • @ThePants999 said:

    Replies to posts should be banned in this forum. We should just have posts, no discussions. I wonder how many awesome WTFs are out there not being posted because the potential posters are worried about getting flamed (or at least mugged) by people who are more interested in judging than in laughing...

    Yeah, that'll help to spread accurate information and stop WTFs from happening.  A large part of this site is debating the validity of the WTFs because there is no True Way and only through argument and consensus can we arrive at any kind of useful conclusion.  If this discourages from people from posting, then all the better.  Either their WTF isn't actually that big of a deal (and they realize this) or they are too sensitive to engage in useful dialogue.  Getting mugged isn't that big of a deal and if your ego is so fragile you can't take a little feedback, I have to wonder at the quality of code you produce as a developer.



  • @morbiuswilters said:

    Getting mugged isn't that big of a deal and if your ego is so fragile you can't take a little feedback, I have to wonder at the quality of code you produce as a developer.

    Aye. Just look at MFD.



  • @ThePants999 said:

    Replies to posts should be banned in this forum. We should just have posts, no discussions. I wonder how many awesome WTFs are out there not being posted because the potential posters are worried about getting flamed (or at least mugged) by people who are more interested in judging than in laughing...

    We'd like to read about the real WTFs, not the lame ones, if you permit.



  • @TheRider said:

    @slyadams said:

    The WTF is the fact that someone thought that providing an integer greater than a range is the only way to misuse such a range.

    I am very sorry to disagree. No, he didn't. He DID check for both ends of the range. He ONLY forgot to show the correct error message on the lower end of the range.

    Are you really this argumentative in real life? Do you always need to have the last word? If everyone had to word themselves so perfectly carefully as to avoid any possible slips or ever so slight ommissions then the world would be a very boring, dry place. I reckon you were the kind of guy that I used to blank out during my CS degree.

    I honestly don't see how posting a little comic error message can cause so much bloody agro on here. It seems there are some people who just come on here to be able to shout at everyone:

     "HA! You might have meant people_array[0]->name, but you wrote people_array[0].name.  You are a fool!!!".

    @TheRider said:

    @slyadams said:

    I really am through trying to explain this now.

    Yep. Let's give peace a chance :-)

     


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.