1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8049632
  27  * @summary Test ClassFileParser::copy_localvariable_table cases
  28  * @library /testlibrary
  29  * @compile -g TestLVT.java
  30  * @run main TestLVT
  31  */
  32 
  33 import com.oracle.java.testlibrary.*;
  34 import java.util.*;
  35 
  36 public class TestLVT {
  37     public static void main(String[] args) throws Exception {
  38         test();  // Test good LVT in this test
  39 
  40         String jarFile = System.getProperty("test.src") + "/testcase.jar";
  41 
  42         // java -cp $testSrc/testcase.jar DuplicateLVT
  43         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-cp", jarFile, "DuplicateLVT");
  44         new OutputAnalyzer(pb.start())
  45             .shouldContain("Duplicated LocalVariableTable attribute entry for 'by' in class file DuplicateLVT")
  46             .shouldHaveExitValue(1);
  47 
  48         // java -cp $testclasses/testcase.jar DuplicateLVTT
  49         pb = ProcessTools.createJavaProcessBuilder("-cp", jarFile, "DuplicateLVTT");
  50         new OutputAnalyzer(pb.start())
  51             .shouldContain("Duplicated LocalVariableTypeTable attribute entry for 'list' in class file DuplicateLVTT")
  52             .shouldHaveExitValue(1);
  53 
  54         // java -cp $testclasses/testcase.jar NotFoundLVTT
  55         pb = ProcessTools.createJavaProcessBuilder("-cp", jarFile, "NotFoundLVTT");
  56         new OutputAnalyzer(pb.start())
  57             .shouldContain("LVTT entry for 'list' in class file NotFoundLVTT does not match any LVT entry")
  58             .shouldHaveExitValue(1);
  59     }
  60 
  61     public static void test() {
  62         boolean b  = true;
  63         byte    by = 0x42;
  64         char    c  = 'X';
  65         double  d  = 1.1;
  66         float   f  = (float) 1.2;
  67         int     i  = 42;
  68         long    l  = 0xCAFEBABE;
  69         short   s  = 88;
  70         ArrayList<String> list = new ArrayList<String>();
  71         list.add("me");
  72 
  73         System.out.println("b=" + b);
  74         System.out.println("by=" + by);
  75         System.out.println("c=" + c);
  76         System.out.println("d=" + d);
  77         System.out.println("f=" + f);
  78         System.out.println("i=" + i);
  79         System.out.println("l=" + l);
  80         System.out.println("s=" + s);
  81         System.out.println("ArrayList<String>=" + list);
  82     }
  83 }