Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8050993

There is no record for condition in ternary operator in LineNumberTable.

XMLWordPrintable

    • b117
    • Verified

      To reproduce run following code
      Expected to see record in line number table for "field % 2 == 0 ?"


      import com.sun.tools.classfile.*;
      import java.io.IOException;
      import java.util.Arrays;

      public class Test {
          public static void main(String[] args) throws IOException, ConstantPoolException {
              ClassFile someTestIn = ClassFile.read(Test.class.getResourceAsStream("Test.class"));
              for (Method m : someTestIn.methods) {
                  if ("method".equals(m.getName(someTestIn.constant_pool))) {
                      Code_attribute code_attribute = (Code_attribute) m.attributes.get(Attribute.Code);
                      for (Attribute at : code_attribute.attributes) {
                          if (Attribute.LineNumberTable.equals(at.getName(someTestIn.constant_pool))) {
                              LineNumberTable_attribute att = (LineNumberTable_attribute) at;
                              Arrays.asList(att.line_number_table).forEach(e -> System.out.println("Line number = " + e.line_number));
                          }
                      }
                  }
              }
              method();
          }

          public static int field;

          public static String method() {
              String s =
                      field % 2 == 0 ? //Breakpoint
                      "true" + field :
                      "false" + field;
              return s;
          }
      }

            jlahoda Jan Lahoda
            anazarov Andrey Nazarov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: