1 /*
2  * Copyright (C) 2020 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 package resolved;
18 
19 import getters.GetPackagePrivateSubclassOfUnresolvedClass2;
20 import unresolved.UnresolvedPublicClass;
21 
22 // This class is defined by the child class loader, so access to
23 // package-private classes and members defined in the parent class
24 // loader is illegal even though the package name is the same.
25 public class PackagePrivateSubclassOfUnresolvedClass2 extends UnresolvedPublicClass {
$noinline$main()26   public static void $noinline$main() {
27     $noinline$testReferrersClass();
28     $noinline$testInlinedReferrersClass();
29     $noinline$testInlinedReferrersClassFromSamePackage();
30 
31     System.out.println("PackagePrivateSubclassOfUnresolvedClass2 passed");
32   }
33 
34   /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass2.$noinline$testReferrersClass() builder (after)
35   /// CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass2 needs_access_check:false
$noinline$testReferrersClass()36   static void $noinline$testReferrersClass() {
37     Class<?> c = PackagePrivateSubclassOfUnresolvedClass2.class;
38   }
39 
40   /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass2.$noinline$testInlinedReferrersClass() inliner (after)
41   // CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass2 needs_access_check:true
$noinline$testInlinedReferrersClass()42   static void $noinline$testInlinedReferrersClass() {
43     // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047
44     Class<?> c = GetPackagePrivateSubclassOfUnresolvedClass2.get();
45   }
46 
47   /// CHECK-START: void resolved.PackagePrivateSubclassOfUnresolvedClass2.$noinline$testInlinedReferrersClassFromSamePackage() inliner (after)
48   // CHECK: LoadClass class_name:resolved.PackagePrivateSubclassOfUnresolvedClass2 needs_access_check:true
$noinline$testInlinedReferrersClassFromSamePackage()49   static void $noinline$testInlinedReferrersClassFromSamePackage() {
50     // Trying to resolve this class by name in parent class loader throws NoClassDefFoundError.
51     try {
52       // TODO: Make $inline$ and enable CHECK above when we relax the verifier. b/28313047
53       Class<?> c = GetPackagePrivateSubclassOfUnresolvedClass2FromSamePackage.get();
54       throw new Error("Unreachable");
55     } catch (NoClassDefFoundError expected) {}
56   }
57 }
58