1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18/**
19 * Exercise monitors.
20 */
21public class Monitor {
22    public static int mVal = 0;
23
24    public synchronized void subTest() {
25        Object obj = new Object();
26        synchronized (obj) {
27            mVal++;
28            obj = null;     // does NOT cause a failure on exit
29            Main.assertTrue(obj == null);
30        }
31    }
32
33
34    public static void run() {
35        System.out.println("Monitor.run");
36
37        Object obj = null;
38
39        try {
40            synchronized (obj) {
41                mVal++;
42            }
43            Main.assertTrue(false);
44        } catch (NullPointerException npe) {
45            /* expected */
46        }
47
48        obj = new Object();
49        synchronized (obj) {
50            mVal++;
51        }
52
53        new Monitor().subTest();
54
55        Main.assertTrue(mVal == 2);
56    }
57}
58