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