Determine whether .class file was compiled with debug info?

If you’re on the command line, then javap -l will display LineNumberTable and LocalVariableTable if present:

peregrino:$ javac -d bin -g:none src/Relation.java 
peregrino:$ javap -classpath bin -l Relation 
public class Relation extends java.lang.Object{
public Relation();

peregrino:$ javac -d bin -g:lines src/Relation.java 
peregrino:$ javap -classpath bin -l Relation 
public class Relation extends java.lang.Object{
public Relation();
  LineNumberTable: 
   line 1: 0
   line 33: 4

peregrino:$ javac -d bin -g:vars src/Relation.java 
peregrino:$ javap -classpath bin -l Relation 
public class Relation extends java.lang.Object{
public Relation();

  LocalVariableTable: 
   Start  Length  Slot  Name   Signature
   0      5      0    this       LRelation;

javap -c will display the source file if present at the start of the decompilation:

peregrino:$ javac -d bin -g:none src/Relation.java 
peregrino:$ javap -classpath bin -l -c Relation | head
public class Relation extends java.lang.Object{
  ...

peregrino:$ javac -d bin -g:source src/Relation.java 
peregrino:$ javap -classpath bin -l -c Relation | head
Compiled from "Relation.java"
public class Relation extends java.lang.Object{
  ...

Programmatically, I’d look at ASM rather than writing yet another bytecode reader.

Leave a Comment