Thu, 23 Oct 2008 18:29:11 +0100
6557954: Inner class type parameters doesn't get substituted when checking type well-formedness
Summary: Validator.visitTypeApply should substitute all formal typevars with actual parameters
Reviewed-by: jjg
duke@1 | 1 | /* |
duke@1 | 2 | * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. |
duke@1 | 8 | * |
duke@1 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 13 | * accompanied this code). |
duke@1 | 14 | * |
duke@1 | 15 | * You should have received a copy of the GNU General Public License version |
duke@1 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 18 | * |
duke@1 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 21 | * have any questions. |
duke@1 | 22 | */ |
duke@1 | 23 | |
duke@1 | 24 | /* |
duke@1 | 25 | * @test |
duke@1 | 26 | * @bug 4116460 |
duke@1 | 27 | * @summary Test access methods for private constructors. |
duke@1 | 28 | * @author William Maddox (maddox) |
duke@1 | 29 | * |
duke@1 | 30 | * @compile ConstructorAccess.java |
duke@1 | 31 | * @run main ConstructorAccess |
duke@1 | 32 | */ |
duke@1 | 33 | |
duke@1 | 34 | public class ConstructorAccess { |
duke@1 | 35 | int i = 0; |
duke@1 | 36 | char c = 'x'; |
duke@1 | 37 | |
duke@1 | 38 | private ConstructorAccess() { |
duke@1 | 39 | this.i = 42; |
duke@1 | 40 | } |
duke@1 | 41 | |
duke@1 | 42 | private ConstructorAccess(int i, char c) { |
duke@1 | 43 | this.i = i; |
duke@1 | 44 | this.c = c; |
duke@1 | 45 | } |
duke@1 | 46 | |
duke@1 | 47 | class Inner { |
duke@1 | 48 | int j; |
duke@1 | 49 | char c; |
duke@1 | 50 | boolean b; |
duke@1 | 51 | |
duke@1 | 52 | private Inner() { |
duke@1 | 53 | this.j = 0; |
duke@1 | 54 | this.b = false; |
duke@1 | 55 | this.c = 'x'; |
duke@1 | 56 | } |
duke@1 | 57 | private Inner(int i, char c) { |
duke@1 | 58 | this.j = i; |
duke@1 | 59 | this.b = true; |
duke@1 | 60 | this.c = c; |
duke@1 | 61 | ConstructorAccess.this.i = i; |
duke@1 | 62 | } |
duke@1 | 63 | private Inner(int i, boolean b) { |
duke@1 | 64 | this.j = i; |
duke@1 | 65 | this.b = b; |
duke@1 | 66 | this.c = 'x'; |
duke@1 | 67 | } |
duke@1 | 68 | void foo() throws Exception { |
duke@1 | 69 | ConstructorAccess x = new ConstructorAccess(); |
duke@1 | 70 | if (x.i != 42 || x.c != 'x') { |
duke@1 | 71 | throw new Exception("error 1"); |
duke@1 | 72 | } |
duke@1 | 73 | ConstructorAccess y = new ConstructorAccess(555, 'y'); |
duke@1 | 74 | if (y.i != 555 || y.c != 'y') { |
duke@1 | 75 | throw new Exception("error2"); |
duke@1 | 76 | } |
duke@1 | 77 | } |
duke@1 | 78 | void check(int j, char c, boolean b) throws Exception { |
duke@1 | 79 | if (this.j != j || this.c != c || this.b != b) { |
duke@1 | 80 | throw new Exception("error3"); |
duke@1 | 81 | } |
duke@1 | 82 | } |
duke@1 | 83 | } |
duke@1 | 84 | |
duke@1 | 85 | void bar() throws Exception { |
duke@1 | 86 | Inner x = new Inner(); |
duke@1 | 87 | x.check(0, 'x', false); |
duke@1 | 88 | x.foo(); |
duke@1 | 89 | Inner y = new Inner(747, 'z'); |
duke@1 | 90 | y.check(747, 'z', true); |
duke@1 | 91 | if (this.i != 747) { |
duke@1 | 92 | throw new Exception("error 4"); |
duke@1 | 93 | } |
duke@1 | 94 | Inner z = new Inner(777, true); |
duke@1 | 95 | z.check(777, 'x' , true); |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | class InnerSub extends Inner { |
duke@1 | 99 | private InnerSub() { |
duke@1 | 100 | super(); |
duke@1 | 101 | } |
duke@1 | 102 | private InnerSub(int i) { |
duke@1 | 103 | super(i, 'w'); |
duke@1 | 104 | } |
duke@1 | 105 | private InnerSub(int i, boolean b) { |
duke@1 | 106 | super(i, b); |
duke@1 | 107 | } |
duke@1 | 108 | } |
duke@1 | 109 | |
duke@1 | 110 | public static void main(String[] args) throws Exception { |
duke@1 | 111 | ConstructorAccess o = new ConstructorAccess(); |
duke@1 | 112 | o.bar(); |
duke@1 | 113 | InnerSub x = o.new InnerSub(); |
duke@1 | 114 | x.check(0, 'x', false); |
duke@1 | 115 | x.foo(); |
duke@1 | 116 | InnerSub y = o.new InnerSub(767); |
duke@1 | 117 | y.check(767, 'w', true); |
duke@1 | 118 | if (o.i != 767) { |
duke@1 | 119 | throw new Exception("error 5"); |
duke@1 | 120 | } |
duke@1 | 121 | InnerSub z = o.new InnerSub(777, true); |
duke@1 | 122 | z.check(777, 'x' , true); |
duke@1 | 123 | } |
duke@1 | 124 | } |