/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {

  public static void main(String[] args) throws ClassNotFoundException {
    try {
      System.out.println(SubClass.SubEnclosed.class.getEnclosingClass());
      throw new Error("Expected NoClassDefFoundError");
    } catch (NoClassDefFoundError e) {
    }
    try {
      System.out.println(SubClass.SuperEnclosed.class.getEnclosingClass());
      throw new Error("Expected NoClassDefFoundError");
    } catch (NoClassDefFoundError e) {
    }

    Class<?> cls = Class.forName("MissingSuperClass$1LocalClass");
    try {
      System.out.println(cls.getEnclosingClass());
      throw new Error("Expected NoClassDefFoundError");
    } catch (NoClassDefFoundError e) {
    }
    try {
      System.out.println(cls.getEnclosingMethod());
      throw new Error("Expected NoClassDefFoundError");
    } catch (NoClassDefFoundError e) {
    }
  }
}

class MissingSuperClass {
  static class SuperEnclosed {}

  static Object returnLocalClass() {
    class LocalClass {}
    return new LocalClass();
  }
}

class SubClass extends MissingSuperClass {
  static class SubEnclosed {}
}

