File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NullPointerException (UnknownSource) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NullPointerException (UnknownSource)" Watch "NullPointerException (UnknownSource)" New topic
Author

NullPointerException (UnknownSource)

Varun Narang
Ranch Hand

Joined: Nov 19, 2004
Posts: 30
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.


Your computer system is like AC, it's of no use when you open Windows ;)
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
To elaborate a little further: In Eclipse 3.2.1: Window->Preferences->Java->Compiler Take a look at the Classfile Generation section.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Or from the command line, use

javac -g MyClass.java

The -g option causes the compiler to include the debugging info you want.


"I'm not back." - Bill Harding, Twister
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
(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
Java Q&A (FAQ, Trivia)
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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


[Jess in Action][AskingGoodQuestions]
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Sorry my mistake.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException (UnknownSource)