Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unknown Source" in java stack trace, yet line numbers are in the class file

Tags:

I've written a super simple java class that is throwing exceptions as it should. However the stack trace I'm getting looks like this:

java.lang.RuntimeException: hello         at Main.go(Unknown Source)         at Main.main(Unknown Source) 

Note: there are no line numbers in the stack trace and I would like there to be.

The answers you find when googling this problem are all about adding the correct parameters at compile time to make sure the line numbers actually make it into the class file. However, I don't believe that's my problem as I have this in my ant build.xml

<javac   debug="true"   debuglevel="lines,vars,source"   includeAntRuntime="false"   classpathref="classpath.compile"   srcdir="${src.dir}"   destdir="${build.classes}" /> 

Also, according to javap, it looks like the line numbers did make it in:

$ javap -l ./build/classes/Main | head -n 9 public class Main extends java.lang.Object{  public Main();   LineNumberTable:     line 14: 0    line 22: 4    line 23: 15    line 24: 26 

So what gives? Is there a param I need to set in the jvm when I run the code?

Thanks!

like image 801
andersonbd1 Avatar asked Feb 09 '12 18:02

andersonbd1


People also ask

What is unknown source in Java?

…it means that the program lacks the relevant debugging information. Specifically the class files are missing the LineNumberTable attribute (JVMS 4.7. 12).

How do I read stack trace errors?

To read this stack trace, start at the top with the Exception's type - ArithmeticException and message The denominator must not be zero . This gives an idea of what went wrong, but to discover what code caused the Exception, skip down the stack trace looking for something in the package com.

What is stack trace exception in Java?

Simply put, a stack trace is a representation of a call stack at a certain point in time, with each element representing a method invocation. The stack trace contains all invocations from the start of a thread until the point it's generated. This is usually a position at which an exception takes place.

What is stack trace exception?

A trace of the method calls is called a stack trace. The stack trace listing provides a way to follow the call stack to the line number in the method where the exception occurs. The StackTrace property returns the frames of the call stack that originate at the location where the exception was thrown.


2 Answers

I think the correct way is:

<javac debug="true" debuglevel="lines,vars,source" 

Note there are no spaces between lines,vars,source

like image 160
bvanvelsen Avatar answered Nov 03 '22 04:11

bvanvelsen


Found this answer on another question:

This is normally related to missing debug information. You are probably using JRE (not JDK), which does not include debug information for rt.jar classes. Try using full JDK, you'll get proper locations in the stack trace

like image 41
shams Avatar answered Nov 03 '22 05:11

shams