Debian Codegraph @

test/2254-class-value-before-and-after-u/src-art/Main.java

raw
1 /*
2 * Copyright (C) 2023 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 import dalvik.system.VMRuntime;
18
19 public class Main {
20 public static void main(String[] args) {
21 VMRuntime.getRuntime().setTargetSdkVersion(0);
22 try {
23 Class classValueClass = Class.forName("java.lang.ClassValue");
24 } catch (ClassNotFoundException ignored) {
25 throw new Error(
26 "java.lang.ClassValue should be available when targetSdkLevel is not set");
27 }
28
29 VMRuntime.getRuntime().setTargetSdkVersion(34);
30
31 try {
32 Class classValueClass = Class.forName("java.lang.ClassValue");
33 } catch (ClassNotFoundException ignored) {
34 throw new Error("java.lang.ClassValue should be available on targetSdkLevel 34");
35 }
36
37 VMRuntime.getRuntime().setTargetSdkVersion(33);
38 try {
39 Class classValueClass = Class.forName("java.lang.ClassValue");
40 throw new Error("Was able to find " + classValueClass + " on targetSdkLevel 33");
41 } catch (ClassNotFoundException expected) {
42 if (!expected.getMessage().contains("java.lang.ClassValue")) {
43 throw new Error("Thrown exception should contain class name, but was: " + expected);
44 }
45 }
46 }
47 }