langtools/test/tools/javac/classfiles/attributes/LineNumberTable/T8050993.java
changeset 37754 7b4f67ce5cb5
child 37755 b0918e7eb16b
equal deleted inserted replaced
37753:dbc87c966861 37754:7b4f67ce5cb5
       
     1 /*
       
     2  * @test /nodynamiccopyright/
       
     3  * @bug 8050993
       
     4  * @summary Verify that the condition in the conditional lexpression gets a LineNumberTable entry
       
     5  * @modules jdk.jdeps/com.sun.tools.classfile
       
     6  * @compile -g T8050993.java
       
     7  * @run main T8050993
       
     8  */
       
     9 
       
    10 import java.io.IOException;
       
    11 import java.util.Arrays;
       
    12 import java.util.HashSet;
       
    13 import java.util.Objects;
       
    14 import java.util.Set;
       
    15 import java.util.stream.Collectors;
       
    16 
       
    17 import com.sun.tools.classfile.*;
       
    18 
       
    19 public class T8050993 {
       
    20     public static void main(String[] args) throws IOException, ConstantPoolException {
       
    21         ClassFile someTestIn = ClassFile.read(T8050993.class.getResourceAsStream("T8050993.class"));
       
    22         Set<Integer> expectedLineNumbers = new HashSet<>(Arrays.asList(48, 49, 46, 47));
       
    23         for (Method m : someTestIn.methods) {
       
    24             if ("method".equals(m.getName(someTestIn.constant_pool))) {
       
    25                 Code_attribute code_attribute = (Code_attribute) m.attributes.get(Attribute.Code);
       
    26                 for (Attribute at : code_attribute.attributes) {
       
    27                     if (Attribute.LineNumberTable.equals(at.getName(someTestIn.constant_pool))) {
       
    28                         LineNumberTable_attribute att = (LineNumberTable_attribute) at;
       
    29                         Set<Integer> actualLinesNumbers = Arrays.stream(att.line_number_table)
       
    30                                                                 .map(e -> e.line_number)
       
    31                                                                 .collect(Collectors.toSet());
       
    32                         if (!Objects.equals(expectedLineNumbers, actualLinesNumbers)) {
       
    33                             throw new AssertionError("Expected LineNumber entries not found;" +
       
    34                                                      "actual=" + actualLinesNumbers + ";" +
       
    35                                                      "expected=" + expectedLineNumbers);
       
    36                         }
       
    37                     }
       
    38                 }
       
    39             }
       
    40         }
       
    41     }
       
    42 
       
    43     public static int field;
       
    44 
       
    45     public static String method() {
       
    46         String s =
       
    47                 field % 2 == 0 ?
       
    48                 "true" + field :
       
    49                 "false" + field;
       
    50         return s;
       
    51     }
       
    52 
       
    53 }