Generated constructor returns from line number of other method

Eirik Bjørsnøs eirbjo at gmail.com
Tue Oct 21 22:19:31 UTC 2014


Hi,

Given a class containing a method switching on an enum, like this:

1:  public class WeirdConstructorLinenumber
2:  {
3:     public void consider(java.math.RoundingMode mode) {
4:         switch ( mode ) {}
5:     }
6:  }

javac generates a default constructor as expected.

But the generated constructor returns from line 4 (which really belongs to
the "consider" method).

I could only make this happen by having my consider method switc on an
enum. If I remove the switch or switch on something different, like an int,
the constructor is generated with a single line and returns at line 1 as
expected.

Could this be a javac bug? Or is there something I'm just completely
missing?

$ javac WeirdConstructorLinenumber.java
$ javap -c -l -classpath . WeirdConstructorLinenumber
Compiled from "WeirdConstructorLinenumber.java"
public class WeirdConstructorLinenumber {
  public WeirdConstructorLinenumber();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method
java/lang/Object."<init>":()V
       4: return
    LineNumberTable:
      line 1: 0
      line 4: 4

   [...]
}


Thanks,
Eirik Bjørsnøs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20141022/5bc99ee9/attachment.html>


More information about the compiler-dev mailing list