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