T7040592.java revision 2869:82a435ed8d1a
160484Sobrien/*
260484Sobrien * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
360484Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
460484Sobrien *
560484Sobrien * This code is free software; you can redistribute it and/or modify it
660484Sobrien * under the terms of the GNU General Public License version 2 only, as
760484Sobrien * published by the Free Software Foundation.
860484Sobrien *
960484Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT
1060484Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1160484Sobrien * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1260484Sobrien * version 2 for more details (a copy is included in the LICENSE file that
1360484Sobrien * accompanied this code).
1460484Sobrien *
1560484Sobrien * You should have received a copy of the GNU General Public License version
1660484Sobrien * 2 along with this work; if not, write to the Free Software Foundation,
1760484Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1860484Sobrien *
1960484Sobrien * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2060484Sobrien * or visit www.oracle.com if you need additional information or have any
2160484Sobrien * questions.
2260484Sobrien */
2360484Sobrien
2460484Sobrien/*
2560484Sobrien * @test
2660484Sobrien * @bug 7040592
2760484Sobrien * @summary Verify that null can be assigned freely to array types without a checkcast
2860484Sobrien */
2960484Sobrien
3060484Sobrienimport java.io.PrintWriter;
3160484Sobrienimport java.io.StringWriter;
3260484Sobrienimport java.nio.file.Paths;
3360484Sobrien
3460484Sobrienpublic class T7040592 {
3560484Sobrien
3660484Sobrien    private static final String assertionErrorMsg =
3760484Sobrien            "null should be assignable to array type without a checkcast";
3860484Sobrien
3960484Sobrien    public static void main(String[] args) {
4060484Sobrien        new T7040592().run();
4160484Sobrien    }
4260484Sobrien
4360484Sobrien    void run() {
4460484Sobrien        check("-c", Paths.get(System.getProperty("test.classes"),
4560484Sobrien                "T7040592_01.class").toString());
4660484Sobrien    }
4760484Sobrien
4860484Sobrien    void check(String... params) {
4960484Sobrien        StringWriter s;
5060484Sobrien        String out;
5160484Sobrien        try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
5260484Sobrien            com.sun.tools.javap.Main.run(params, pw);
5360484Sobrien            out = s.toString();
5460484Sobrien        }
5560484Sobrien        if (out.contains("checkcast")) {
5660484Sobrien            throw new AssertionError(assertionErrorMsg);
5760484Sobrien        }
5860484Sobrien    }
5960484Sobrien
6060484Sobrien}
6160484Sobrien
6260484Sobrienclass T7040592_01 {
6360484Sobrien    static void handleArrays(Object [] a, Object [][] b, Object [][][] c) {
6460484Sobrien    }
6560484Sobrien    public static void main(String[] args) {
6660484Sobrien        Object a[];
6760484Sobrien        Object o = (a = null)[0];
6860484Sobrien        Object b[][];
6960484Sobrien        o = (b = null)[0][0];
7060484Sobrien        Object c[][][];
7160484Sobrien        o = (c = null)[0][0][0];
7260484Sobrien        handleArrays(null, null, null);
7360484Sobrien    }
7460484Sobrien}
7560484Sobrien