Tuesday, February 19, 2008

Line numbers in Java Exception Stack Trace

This post is almost like a note in my java diary. I came across this problem while using the ant javac task. My javac task looked like this:

<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath>
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</classpath>
</javac>


No real problems right? Except the fact that when an exception occured in the code compiled using this task I usually got something like this:

Exception in thread "main" java.lang.NullPointerException: Null
at SampleTrace.main(Unknown Source)

See that "Unknown Source" thing? It makes debugging an unusually hard task. So whats the problem here? The problem is the two attributes of the javac task debug and deubglevel.
These options translate into the -g command line option for javac. These options relate to how much debugging information will be present in class files generated. You can give a combination of three values for this option

  • lines - Line number debugging information.
  • vars - Local variable debugging information.
  • source - Source file debugging information.
Of course, more the debugging information the bigger your class files become. So what do these options really mean in terms of getting an exception stack trace in my program to show me line numbers. My initially understanding was that all I needed was line so that I could get line number information. Right? Wrong! If you are just looking for solution without knowing about the why of it, the answer is:
lines,source - i.e. Make debug="on" and debuglevel="lines,source" in you javac task.

The most important thing to understand is what does the combination of these options do:
  • lines,vars,source - Include all debugging information
  • lines,vars - Include line number information, preserve variable names for method local variables. Line number information is especially useful if you are going to use a debugger to debug your programs.
  • lines,source - line number information and source file information. This is what is required for exception stack trace to work properly.
  • vars,source - Preserve method local variable names as well as source file information.
The source option is what still remains a confusion point. I have tried compiling my class files without that option, but no apparent changes are reflected in my class file as viewed in the decompiler. So any comments are welcome :-)

25 comments :

Sunil said...

Excellent Post!! Straight to the point, and thanks for giving a detailed explanation as well.

Anonymous said...

Good words.

Anonymous said...

Excellent Post!! Thanks for giving a detailed explanation for the point.

Anonymous said...

Excellent.. Thanks- sathya

Shaz said...

Thanks.
-Shashank :)

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

After reading your this blog, I thought your blog is great! i like it .thank you!

Anonymous said...

I want to thank the blogger very much not only for this post but also for his all previous efforts. I found blog.puneetlakhina.com to be extremely interesting. I will be coming back to blog.puneetlakhina.com for more information.

Anonymous said...

[url=http://seghan.ru/go.php?sid=2][img]http://banners.servized.com/current/gif/pharm_720x90_1.gif[/img][/url]

[url=http://old-drugstore.net/]What is/are Zovirax Tablets?[/url]
What are acyclovir tablets or capsules?
ACYCLOVIR (Zovirax®) treats unerring types of viral infections, specifically herpes infections. Acyclovir
determination not panacea herpes infections; it see fit remedy the sores heal faster and eschew to ease the pain or discomfort.
Sometimes acyclovir is postulated to improve enjoin the infection from coming back. Acyclovir also treats shingles
and chickenpox infections. Generic acyclovir tablets and capsules are available.

What should I communicate my fitness distress provider ahead I crook this medicine?
They needfulness to know if you comprise any of these conditions:

•dehydration
•neurological blight
•kidney disease
•seizures (convulsions)
•an peculiar or allergic reaction to acyclovir, ganciclovir, valacyclovir, valganciclovir, other medicines, foods, dyes, or preservatives
•significant or distressing to secure in a family way
•breast-feeding



[url=http://best-drugstore.aoaoaxxx.ru/][img]http://i079.radikal.ru/0910/b9/3f666eb40896.jpg[/img][/url]
























[url= ]overnight delivery on Zoviraxcash on delivery Zovirax no rx [/url]
Zovirax online purchase saturday deliveryZovirax without prescription cash on delivery
[url= ]buy cheap discount online Zoviraxcod delivery overnight Zovirax [/url]
Zovirax and cod saturday deliveryZovirax money order
[url= ]medicine Zoviraxcheap order Zovirax [/url]
Zovirax pain managementZovirax cash on delivery without doctors prescription
[url= ]Zovirax free consultation fedex overnight delivery50 mg Zovirax [/url]
cod Zovirax cash on deliveryZovirax overnight delivery
[url= ]next day delivery Zoviraxbuy Zovirax from online pharmacy with saturday delivery [/url]
buy Zovirax free fedex shippingonline Zovirax fedex next day delivery
[url= ]buy Zovirax cod overnightcheap Zovirax cod delivery [/url]
Zovirax online deliverycheapest Zovirax free delivery
[url= ]order Zovirax cod overnight deliverycheap Zovirax buy online [/url]
buying Zovirax onlineZovirax pharmacies accepting cod delivery
[url= ]Zovirax overnight delivery no prescriptiononline ordering Zovirax [/url]
buy prescription Zoviraxorder Zovirax for over night delivery
[url= ]cheap order prescription Zoviraxcod pharmacy Zovirax [/url]
cheap Zovirax delivery fedexbuy cheap Zovirax no prescription
[url= ]cheap Zovirax overnight saturday delivery120 tabs Zovirax [/url]
order Zovirax onlinebuy cheap discounted Zovirax

Anonymous said...

singles travel tours [url=http://loveepicentre.com/]baby boomer dating site[/url] bogota marriage dating apartments http://loveepicentre.com/ stocks backdating

Anonymous said...

I do think this is a most incredible website for proclaiming great wonders of Our God!

Anonymous said...

Hi everyone

We do not agree with this year Brit awards decision.

Please attend our little web poll

http://micropoll.com/t/KDqOnZBCWt

Lady Gaga can not be better than heavy metal

Poll supported by BRIT awards 2010 sponsor femmestyle
[url=http://www.femmestyle.ch/tips/index.html]nach schönheitsoperationen[/url]

BRITs.co.uk - tickets left standing!! This Competition is now closed
OK

Anonymous said...

Genial brief and this fill someone in on helped me alot in my college assignement. Thanks you as your information.

Anonymous said...

Smash readied [url=http://itkyiy.com/lasonic-lta-260/]lta chile[/url] just fine [url=http://itkyiy.com/methylprednisolone-acetate/]methylprednisolone and alcohol[/url] hollow eye [url=http://itkyiy.com/sces/]sce discounts[/url] his book [url=http://itkyiy.com/k-chlor/]atenolol chlor[/url] continued exile [url=http://itkyiy.com/epipen-online-video/]epipen and production and cost[/url] had hoped [url=http://itkyiy.com/bio-identical-estrogens/]overweight women estrogens hairy[/url] ask brothers [url=http://itkyiy.com/vertigo-meclizine/]side effects of meclizine[/url] and get [url=http://itkyiy.com/goody's-credit-card-bill/]goody's warn notice[/url] the completion [url=http://itkyiy.com/sodium-xylene-sulfonate/]barium diphenylamine sulfonate[/url] human genes [url=http://itkyiy.com/technetium-99m/]technetium ecd[/url] and basilisks [url=http://itkyiy.com/siberian-ginseng-increasing-testosterone/]ginseng and medicine[/url] much cake [url=http://itkyiy.com/dr-jonas-salk-biography/]salk contemporary[/url] should find [url=http://itkyiy.com/fond-du-lac-reservation-tribal-enrollment/]fond du lac wi newspaper[/url] toward her [url=http://itkyiy.com/tramadol-vs-vicodin/]online pharmacy vicodin hydrocodone[/url] her immediate [url=http://itkyiy.com/removing-chlorine-with-sodium-thiosulfate/]sodium thiosulfate vs hydrochloric acid[/url] horrific implicatio [url=http://itkyiy.com/peekaboo-petites/]cleo petites[/url] their sea [url=http://itkyiy.com/tummy-tucks-brooklyn/]table that tucks into sofa[/url] watch out [url=http://itkyiy.com/turbo-backup-pep/]pep plus turbo backup[/url] other necessitie [url=http://itkyiy.com/diphenhydramine-lawsuits/]diphenhydramine hcl for sleep[/url] the dusky [url=http://itkyiy.com/ethyl-epa-purified/]purified compressed air[/url] and clunked profanity.

Anonymous said...

Correctly your article helped me very much in my college assignment. Hats high to you send, intention look ahead in the direction of more cognate articles soon as its anecdote of my pick subject-matter to read.

viagra online said...

Hello friend excellent and very interesting post about Line numbers in Java Exception Stack Trace thanks for sharing!!

Travelopati said...

Even in the most sexually liberated and self-satisfied of nations, many people still yearn to burn more, to feel ready for bedding no matter what the clock says and to desire their partner of 23 years as much as they did when their love was brand new.
The market is saturated with books on how to revive a flagging libido or spice up monotonous sex, and sex therapists say “lack of desire” is one of the most common complaints they hear from patients, particularly women.

Unknown said...

Wow that's an amzingly inspiring list. Given me quite a few ideas of now to start on them.
aldactone 100 mg

Unknown said...

Excellent Post!! Straight to the point, and thanks for giving a detailed explanation as well.


http://www.sundrugstore.com/clarinex-c-21_130.html
clarinex

Unknown said...

http://www.sundrugstore.com/claritin-c-21_131.html
claritin

ricky ponting said...

http://www.sundrugstore.com/colospa-c-28_279.htmlcolospa online

ricky ponting said...

http://www.sundrugstore.com/combivir-c-31_88.html combivir online

ricky ponting said...

http://www.sundrugstore.com/cozaar-c-294_309.html cozaar online

Unknown said...

Hello,
Thank you for sharing valuable information. Nice post. I enjoyed reading this post.

Thanks and Regards
www.sureviagra.com/