Channels ▼

Jocelyn Paine

Dr. Dobb's Bloggers

My Least Favourite Error Messages

February 14, 2010

My least favourite error messages are Java's array-index-out-of-bounds and null-pointer ones, as in:

Exception in thread "main" java.lang.NullPointerException<br />        at mystuff.prog.main(prog.java:11) <br />
where Java refuses to tell me which variable holds the empty pointer or faulty array index. This is no small irritation when one is calling a method that takes seventeen pointer arguments, any of which could be null.

Granted, it does at least deign to tell me the line number, and given its ineptitude with variable names, I am amazed it can do so. One imagines Java standing at a rain barrel full of tombola slips, as at a village fête. Scribbled on each slip is a statement and its line number; scrabbling through them all is Java, trying to find the slip whose statement text matches mine so it can report the corresponding line number.

Perhaps I'm being unfair to Java, but then again, perhaps I'm not. For its compiler messages are no better. You've written your program — it might be, let us say, an eigenvector finder for medical data reduction — and you have just completed the method for printing the results. A very nice method it is too, with ever so many options:

private static void printEigenvectors( int indentation<br />                                     , short line_spacing <br />                                     , boolean whether_pdf<br />                                     , float page_magnification<br />                                     , char vector_component_separator<br />                                     , double[][] eigenvectors<br />                                     , String page_title <br />                                     , java.io.PrintStream output_to <br />                                     )<br />

But it's half past five already, and you really really want to see the results before you meet your mates at the pub. So you fling the program at the compiler as you grab your wellies and umbrella and get ready to set off. But what does Java come back with? This, and this only:

prog.java:13: printEigenvectors(int,short,boolean,float,char,<br />double[][],java.lang.String,java.io.PrintStream) in <br />mystuff.prog cannot be applied to (int,short,boolean,float,<br />char,java.lang.String,java.io.PrintStream)<br />    printEigenvectors( 4, 1,<br />    ^<br />1 error<br />

Is that easy to read, or does some compiler writer need to learn the word "ergonomic"? Surely, you mutter as you text a friend your food order because now you're going to be late, Java could apply a bit of nous, say a minimum-edit-distance between the formals and the actuals to tell you the type and position of the missing argument?

Even better would be a smidgen of context-dependence:

prog.java:13: <br />Dear Jocelyn,<br />you have an argument missing from your call to printEigenvectors <br />on line 13. I suspect it to be the double[][], local parameter <br />"eigenvectors".<br /><br />I have examined the method that calls printEigenvectors,<br />and I see that it has an unused variable named <br />"principal_component_eivects". Because "eivects" is <br />likely to be an abbreviation for "eigenvectors", and<br />because Principal Component Analysis uses eigenvectors<br />for its principal components, I suspect this variable to be <br />your missing argument.<br /><br />I have therefore recoded the method call so that it binds <br />"principal_component_eivects" to "eigenvectors". I then ran <br />the program, and sent the output to the best-quality printer in the<br />office, the upstairs one with the magnolia 125-gsm paper in it. <br />If I have recoded the method wrongly, thereby wasting the<br />paper, please contact Sun's Java team, who will refund<br />its cost.<br />

Sun, I hope you're reading this. But I shan't be truly satisfied until Java knows enough to stand me a pint at the pub. With such intelligence, though, it will probably insist on me standing it one.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video