EarlyAssert.java revision 553:9d9f26857129
10SN/A/*
2157SN/A * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved.
30SN/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
40SN/A *
50SN/A * This code is free software; you can redistribute it and/or modify it
60SN/A * under the terms of the GNU General Public License version 2 only, as
7157SN/A * published by the Free Software Foundation.
80SN/A *
9157SN/A * This code is distributed in the hope that it will be useful, but WITHOUT
100SN/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
110SN/A * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
120SN/A * version 2 for more details (a copy is included in the LICENSE file that
130SN/A * accompanied this code).
140SN/A *
150SN/A * You should have received a copy of the GNU General Public License version
160SN/A * 2 along with this work; if not, write to the Free Software Foundation,
170SN/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
180SN/A *
190SN/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
200SN/A * or visit www.oracle.com if you need additional information or have any
21157SN/A * questions.
22157SN/A */
23157SN/A
240SN/A/*
250SN/A * @test
260SN/A * @bug 4402864
270SN/A * @summary Verify that assertions are enabled before the class is initialized
280SN/A * and not thereafter
290SN/A * @author gafter
300SN/A * @build EarlyAssert EarlyAssertWrapper
310SN/A * @run main EarlyAssertWrapper
320SN/A */
330SN/A
340SN/A/*
350SN/A * Verify that assertions are enabled until the class is initialized
360SN/A */
370SN/A
380SN/Aclass EASuper {
390SN/A    static {
400SN/A        EarlyAssert.foo();
410SN/A    }
420SN/A}
430SN/A
440SN/Apublic class EarlyAssert extends EASuper {
450SN/A    static public void foo() {
460SN/A        boolean assertionStatus = false;
470SN/A        assert assertionStatus = true;
480SN/A        if (!assertionStatus) {
490SN/A            throw new Error("Assertions are not enabled before initialization as they should be.");
500SN/A        }
510SN/A    }
520SN/A    public static void main(String[] args) {
530SN/A        boolean assertionStatus = false;
540SN/A        assert assertionStatus = true;
550SN/A        if (assertionStatus) {
560SN/A            throw new Error("Assertions are not disabled after initialization as they should be.");
570SN/A        }
580SN/A    }
590SN/A}
600SN/A