duke@1: /* ohair@554: * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: /* duke@1: * @test duke@1: * @bug 4116460 duke@1: * @summary Test access methods for private constructors. duke@1: * @author William Maddox (maddox) duke@1: * duke@1: * @compile ConstructorAccess.java duke@1: * @run main ConstructorAccess duke@1: */ duke@1: duke@1: public class ConstructorAccess { duke@1: int i = 0; duke@1: char c = 'x'; duke@1: duke@1: private ConstructorAccess() { duke@1: this.i = 42; duke@1: } duke@1: duke@1: private ConstructorAccess(int i, char c) { duke@1: this.i = i; duke@1: this.c = c; duke@1: } duke@1: duke@1: class Inner { duke@1: int j; duke@1: char c; duke@1: boolean b; duke@1: duke@1: private Inner() { duke@1: this.j = 0; duke@1: this.b = false; duke@1: this.c = 'x'; duke@1: } duke@1: private Inner(int i, char c) { duke@1: this.j = i; duke@1: this.b = true; duke@1: this.c = c; duke@1: ConstructorAccess.this.i = i; duke@1: } duke@1: private Inner(int i, boolean b) { duke@1: this.j = i; duke@1: this.b = b; duke@1: this.c = 'x'; duke@1: } duke@1: void foo() throws Exception { duke@1: ConstructorAccess x = new ConstructorAccess(); duke@1: if (x.i != 42 || x.c != 'x') { duke@1: throw new Exception("error 1"); duke@1: } duke@1: ConstructorAccess y = new ConstructorAccess(555, 'y'); duke@1: if (y.i != 555 || y.c != 'y') { duke@1: throw new Exception("error2"); duke@1: } duke@1: } duke@1: void check(int j, char c, boolean b) throws Exception { duke@1: if (this.j != j || this.c != c || this.b != b) { duke@1: throw new Exception("error3"); duke@1: } duke@1: } duke@1: } duke@1: duke@1: void bar() throws Exception { duke@1: Inner x = new Inner(); duke@1: x.check(0, 'x', false); duke@1: x.foo(); duke@1: Inner y = new Inner(747, 'z'); duke@1: y.check(747, 'z', true); duke@1: if (this.i != 747) { duke@1: throw new Exception("error 4"); duke@1: } duke@1: Inner z = new Inner(777, true); duke@1: z.check(777, 'x' , true); duke@1: } duke@1: duke@1: class InnerSub extends Inner { duke@1: private InnerSub() { duke@1: super(); duke@1: } duke@1: private InnerSub(int i) { duke@1: super(i, 'w'); duke@1: } duke@1: private InnerSub(int i, boolean b) { duke@1: super(i, b); duke@1: } duke@1: } duke@1: duke@1: public static void main(String[] args) throws Exception { duke@1: ConstructorAccess o = new ConstructorAccess(); duke@1: o.bar(); duke@1: InnerSub x = o.new InnerSub(); duke@1: x.check(0, 'x', false); duke@1: x.foo(); duke@1: InnerSub y = o.new InnerSub(767); duke@1: y.check(767, 'w', true); duke@1: if (o.i != 767) { duke@1: throw new Exception("error 5"); duke@1: } duke@1: InnerSub z = o.new InnerSub(777, true); duke@1: z.check(777, 'x' , true); duke@1: } duke@1: }