• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException (UnknownSource)

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
This is a little strange problem.
I've written some source code in Java using Eclipse and I am running it thro' Eclipse. When and if a NullPointerException is thrown, Exception log gives all information about the line which threw the Exception and all.
Now I create a Jar file of my compiled files and put this jar into the classpath, But now if there is NullPointerException, then all it says is
NullPointerException <<CLASS-NAME.METHOD-NAME>> (unknownSource), when run.
Can anyone suggest any idea of how to print the exact line no. which threw the Exception.

Thanks a lot for the great help.
Regards,
Varun Narang.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The source has been compiled with no debug information argument.So I do not think that you can find the line number of the faulty code.
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To elaborate a little further: In Eclipse 3.2.1: Window->Preferences->Java->Compiler Take a look at the Classfile Generation section.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or from the command line, use

javac -g MyClass.java

The -g option causes the compiler to include the debugging info you want.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(Unknown Source) comes from VMs that perform "tail call optimisation". This excludes the Sun VM[1], so I'll assume you're using the IBM VM[2]. If I remember rightly[3], there is a switch to the VM to prevent this optimisation. The -g option has nothing to do with anything so you can ignore that little red herring.

[1] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4726340 Many will claim that Java will die without this RFE filled and I almost agree (I believe it will die anyway, but without this RFE, it will die sooner). This prediction is based on trends within the industry i.e. the invention of functional programming in Java which doesn't cater well for it. You can read about it On the flip side, the .NET VM includes a tail call instruction (and thus, tail call elimination), which allows "dysfunctional" (impure) languages to compile easily to the platform such as F# (an ML-based impure FP language).

[2] For fun, try this code on Sun VM:

It fails with stack overflow.
Now run it on the IBM VM. It will probably run forever - if it fails, just run it again until eventually (usually immediately or soon thereafter) the VM will optimise the tail call in which case you are in an infinite loop with constant stack size. This is where your "Unknown Source" comes from - the tail call has been eliminated.

[3] ..since last working for The Filth on the IBM VM last year and seldom touching Java since.
[ December 08, 2006: Message edited by: Tony Morris ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, just realised it was the beginner's forum - excuse my excessive rant if you don't understand it.

"Unknown Source" comes from VMs that perform "tail call elimination" (this generally means IBM and not Sun). Find the switch to turn it off and run again - you should now have a more meaningful stack trace.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Viz:



Jim's advice about needing to use -g is out of date, but his explanation isn't. You get "Unknown Source" whenever a class file doesn't include line number tables, as we get with the -g:none switch. There are doubtless various circumstances that can give rise to this, including those that Tony mentions -- but Occam would prefer my answer here I believe
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry my mistake.
reply
    Bookmark Topic Watch Topic
  • New Topic