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  * @modules java.base/sun.misc
  30  *          java.management
  31  * @compile -g -XDignore.symbol.file TestLVT.java
  32  * @run main TestLVT
  33  */
  34 
  35 import jdk.test.lib.*;
  36 import java.util.*;
  37 
  38 public class TestLVT {
  39     public static void main(String[] args) throws Exception {
  40         test();  // Test good LVT in this test
  41 
  42         String jarFile = System.getProperty("test.src") + "/testcase.jar";
  43 
  44         // java -cp $testSrc/testcase.jar DuplicateLVT
  45         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-cp", jarFile, "DuplicateLVT");
  46         new OutputAnalyzer(pb.start())
  47             .shouldContain("Duplicated LocalVariableTable attribute entry for 'by' in class file DuplicateLVT")
  48             .shouldHaveExitValue(1);
  49 
  50         // java -cp $testclasses/testcase.jar DuplicateLVTT
  51         pb = ProcessTools.createJavaProcessBuilder("-cp", jarFile, "DuplicateLVTT");
  52         new OutputAnalyzer(pb.start())
  53             .shouldContain("Duplicated LocalVariableTypeTable attribute entry for 'list' in class file DuplicateLVTT")
  54             .shouldHaveExitValue(1);
  55 
  56         // java -cp $testclasses/testcase.jar NotFoundLVTT
  57         pb = ProcessTools.createJavaProcessBuilder("-cp", jarFile, "NotFoundLVTT");
  58         new OutputAnalyzer(pb.start())
  59             .shouldContain("LVTT entry for 'list' in class file NotFoundLVTT does not match any LVT entry")
  60             .shouldHaveExitValue(1);
  61     }
  62 
  63     public static void test() {
  64         boolean b  = true;
  65         byte    by = 0x42;
  66         char    c  = 'X';
  67         double  d  = 1.1;
  68         float   f  = (float) 1.2;
  69         int     i  = 42;
  70         long    l  = 0xCAFEBABE;
  71         short   s  = 88;
  72         ArrayList<String> list = new ArrayList<String>();
  73         list.add("me");
  74 
  75         System.out.println("b=" + b);
  76         System.out.println("by=" + by);
  77         System.out.println("c=" + c);
  78         System.out.println("d=" + d);
  79         System.out.println("f=" + f);
  80         System.out.println("i=" + i);
  81         System.out.println("l=" + l);
  82         System.out.println("s=" + s);
  83         System.out.println("ArrayList<String>=" + list);
  84     }
  85 }