1/* 2 * Copyright (c) 2013, 2016, 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 8003537 27 * @summary javap should not use / in Bounds Type Variables 28 * @modules jdk.jdeps/com.sun.tools.javap 29 */ 30 31import java.io.File; 32import java.io.IOException; 33import java.io.PrintWriter; 34import java.io.StringWriter; 35import java.nio.charset.Charset; 36import java.nio.file.Files; 37import java.util.ArrayList; 38import java.util.List; 39import java.util.regex.Pattern; 40import static java.nio.file.StandardOpenOption.*; 41 42public class BoundsTypeVariableTest { 43 public static void main(String... args) throws Exception { 44 new BoundsTypeVariableTest().run(); 45 } 46 47 void run() throws Exception { 48 File srcDir = new File("src"); 49 srcDir.mkdirs(); 50 File classesDir = new File("classes"); 51 classesDir.mkdirs(); 52 final String expect = "public abstract <U extends java.lang.Object> U doit();"; 53 List<String> contents = new ArrayList<>(); 54 contents.add("abstract class X {"); 55 contents.add(expect); 56 contents.add("}"); 57 58 File f = writeFile(new File(srcDir, "X.java"), contents); 59 javac("-d", classesDir.getPath(), f.getPath()); 60 String out = javap("-p", "-v", new File(classesDir, "X.class").getPath()); 61 if (!out.contains(expect)) { 62 throw new Exception("expected pattern not found: " + expect); 63 } 64 } 65 66 File writeFile(File f, List<String> body) throws IOException { 67 Files.write(f.toPath(), body, Charset.defaultCharset(), 68 CREATE, TRUNCATE_EXISTING); 69 return f; 70 } 71 72 void javac(String... args) throws Exception { 73 StringWriter sw = new StringWriter(); 74 PrintWriter pw = new PrintWriter(sw); 75 int rc = com.sun.tools.javac.Main.compile(args, pw); 76 pw.flush(); 77 String out = sw.toString(); 78 if (!out.isEmpty()) 79 System.err.println(out); 80 if (rc != 0) 81 throw new Exception("compilation failed"); 82 } 83 84 String javap(String... args) throws Exception { 85 StringWriter sw = new StringWriter(); 86 PrintWriter pw = new PrintWriter(sw); 87 int rc = com.sun.tools.javap.Main.run(args, pw); 88 pw.flush(); 89 String out = sw.toString(); 90 if (!out.isEmpty()) 91 System.err.println(out); 92 if (rc != 0) 93 throw new Exception("javap failed"); 94 return out; 95 } 96} 97