1/*
2 * Copyright (C) 2013 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 * Testing check-cast, see comment in info.txt
19 */
20
21class B {}
22class D extends B {}
23
24public class Main {
25    public static void main(String args[]) {
26        B b = null;
27        try {
28            if (1 == args.length) {
29                b = new B();
30            } else {
31                b = new D();
32            }
33            D d = (D) b;
34            if (!(b instanceof D)) {
35                System.out.println("Error: No ClassCastException throuwn when it should have been.");
36            } else {
37                System.out.println("OK");
38            }
39        }
40        catch (ClassCastException cce) {
41            if (b instanceof D) {
42                System.out.println("Error: ClassCastException thrown when it shouldn't have been.");
43            } else {
44                System.out.println("OK");
45            }
46        }
47    }
48}
49