Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Apr 16, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Line Numbers Missing From Stack Trace

You may have seen "(Compiled Code)" in a stack trace and wondered why a line number was not displayed instead. This occurs because as of release 1.1.5 of the Java Development Kit (JDK), the default behavior is to use a Just-In-Time (JIT) compiler. Once the JIT compiler has processed the code, the line numbers no longer exist and cannot be displayed. For example:
public class jitest {
	public static void main(String[] args)
					throws Exception {
		jitest jt = new jitest();
	}  //  public static void main()

	public jitest() throws Exception {
	}  //  public jitest()

	private void runtest() throws Exception {
		for (int i = 0; i < 10000; i++) {};
		throw new Exception("No line numbers");
	}  //  private void runtest()
}  //  public class jitest
Running this code with the Java Virtual Machine (JVM) from 1.1.5 or later will produce this stack trace when the exception is thrown:
java.lang.Exception: No line numbers
	at java.lang.Throwable.(Compiled Code)
	at jitest.runtest(Compiled Code)
	at jitest.(jitest.java:8)
	at jitest.main(jitest.java:4)
Notice that the stack trace does not identify the specific line where the exception was thrown, but merely reads "(Compiled Code)". In this trivial example, it's obvious where the exception was generated, but in a more complex class, it can be very difficult to determine where, for example, a NullPointerException occurred. To get around this behavior, you can temporarily disable the JIT using a command-line option. For a Java 1.1.x JVM, use the
Brett Spell
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date