langtools/test/tools/javac/6627362/T6627362.java
author xdono
Thu, 02 Oct 2008 19:58:40 -0700
changeset 1264 076a3cde30d5
parent 1037 c6b315a34dc6
child 3776 c516c9b3fb72
permissions -rw-r--r--
6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
     1
/*
1264
076a3cde30d5 6754988: Update copyright year
xdono
parents: 1037
diff changeset
     2
 * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
     4
 *
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
     8
 *
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    13
 * accompanied this code).
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    14
 *
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    18
 *
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    21
 * have any questions.
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    22
 */
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    23
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    24
/*
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    25
 * @test
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    26
 * @bug 6627362
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    27
 * @summary javac generates code that uses array.clone,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    28
 *          which is not available on JavaCard
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    29
 */
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    30
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    31
import java.io.*;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    32
import java.lang.reflect.*;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    33
import java.net.*;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    34
import java.util.*;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    35
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    36
public class T6627362 {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    37
    static String testSrc = System.getProperty("test.src", ".");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    38
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    39
    public static void main(String... args) throws Exception {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    40
        new T6627362().run();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    41
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    42
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    43
    public void run() throws Exception {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    44
        testStandard();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    45
        testNoClone();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    46
        if (errors > 0)
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    47
            throw new Error(errors + " test cases failed");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    48
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    49
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    50
    void testStandard() throws Exception {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    51
        // compile and disassemble E.java, check for reference to Object.clone()
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    52
        File x = new File(testSrc, "x");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    53
        String[] jcArgs = { "-d", ".",
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    54
                            new File(x, "E.java").getPath() };
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    55
        compile(jcArgs);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    56
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    57
        String[] jpArgs = { "-classpath", ".", "-c", "E" };
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    58
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    59
        StringWriter sw = new StringWriter();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    60
        javap(new PrintWriter(sw, true), jpArgs);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    61
        check(sw.toString(), "Method \"[LE;\".clone:()Ljava/lang/Object;");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    62
        callValues();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    63
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    64
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    65
    void testNoClone() throws Exception {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    66
        // compile and disassemble E.java, using modified Object.java,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    67
        // check for reference to System.arraycopy
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    68
        File x = new File(testSrc, "x");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    69
        String[] jcArgs = { "-d", ".",
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    70
                            new File(x, "E.java").getPath(),
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    71
                            new File(x, "Object.java").getPath()};
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    72
        compile(jcArgs);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    73
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    74
        String[] jpArgs = { "-classpath", ".", "-c", "E" };
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    75
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    76
        StringWriter sw = new StringWriter();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    77
        javap(new PrintWriter(sw, true), jpArgs);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    78
        check(sw.toString(), "//Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    79
        callValues();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    80
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    81
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    82
    void compile(String... args) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    83
        int rc = com.sun.tools.javac.Main.compile(args);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    84
        if (rc != 0)
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    85
            throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    86
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    87
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    88
    void javap(PrintWriter out, String... args) throws Exception {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    89
        // for now, we have to exec javap
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    90
        File javaHome = new File(System.getProperty("java.home"));
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    91
        if (javaHome.getName().equals("jre"))
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    92
            javaHome = javaHome.getParentFile();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    93
        File javap = new File(new File(javaHome, "bin"), "javap");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    94
        String[] cmd = new String[args.length + 1];
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    95
        cmd[0] = javap.getPath();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    96
        System.arraycopy(args, 0, cmd, 1, args.length);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    97
        Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    98
        p.getOutputStream().close();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    99
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   100
        String line;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   101
        while ((line = in.readLine()) != null)
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   102
            out.println(line);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   103
        int rc = p.waitFor();
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   104
        if (rc != 0)
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   105
            throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   106
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   107
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   108
    void check(String s, String require) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   109
        if (s.indexOf(require) == -1) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   110
            System.err.println("Can't find " + require);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   111
            errors++;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   112
        }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   113
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   114
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   115
    void callValues() {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   116
        try {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   117
            File dot = new File(System.getProperty("user.dir"));
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   118
            ClassLoader cl = new URLClassLoader(new URL[] { dot.toURL() });
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   119
            Class<?> e_class = cl.loadClass("E");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   120
            Method m = e_class.getMethod("values", new Class[] { });
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   121
            //System.err.println(m);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   122
            Object o = m.invoke(null, (Object[]) null);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   123
            List<Object> v = Arrays.asList((Object[]) o);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   124
            if (!v.toString().equals("[a, b, c]"))
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   125
                throw new Error("unexpected result for E.values(): " + v);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   126
        } catch (Exception e) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   127
            throw new Error(e);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   128
        }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   129
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   130
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   131
    int errors;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   132
}
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   133