langtools/test/tools/javac/6627362/T6627362.java
author juh
Tue, 25 Jun 2013 14:31:29 -0700
changeset 18551 882a3948c6e6
parent 5520 86e4b9a9da40
child 30730 d3ce7619db2c
permissions -rw-r--r--
8017325: Cleanup of the javadoc <code> tag in java.security.cert Summary: Convert javadoc <code>...</code> and <tt>...</tt> tags to {@code ...} Reviewed-by: darcy
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
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
diff changeset
     2
 * Copyright (c) 2007, 2009, Oracle and/or its affiliates. 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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
diff changeset
    21
 * questions.
1037
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);
3776
c516c9b3fb72 6877751: test/tools/javac/6627362/T6627362.java fails
jjg
parents: 1264
diff changeset
    78
        check(sw.toString(), "// Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V");
1037
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 {
3776
c516c9b3fb72 6877751: test/tools/javac/6627362/T6627362.java fails
jjg
parents: 1264
diff changeset
    89
        int rc = com.sun.tools.javap.Main.run(args, out);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    90
        if (rc != 0)
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    91
            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
    92
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    93
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    94
    void check(String s, String require) {
3776
c516c9b3fb72 6877751: test/tools/javac/6627362/T6627362.java fails
jjg
parents: 1264
diff changeset
    95
        System.out.println("Checking:\n" + s);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    96
        if (s.indexOf(require) == -1) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    97
            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
    98
            errors++;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
    99
        }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   100
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   101
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   102
    void callValues() {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   103
        try {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   104
            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
   105
            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
   106
            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
   107
            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
   108
            //System.err.println(m);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   109
            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
   110
            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
   111
            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
   112
                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
   113
        } catch (Exception e) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   114
            throw new Error(e);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   115
        }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   116
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   117
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   118
    int errors;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   119
}
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
diff changeset
   120