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 import java.lang.reflect.Constructor; 18 import java.lang.reflect.Method; 19 20 public class Main { 21 public static String TEST_NAME = "727-checker-unresolved-class"; 22 getClassLoaderFor(String location)23 public static ClassLoader getClassLoaderFor(String location) throws Exception { 24 try { 25 Class<?> class_loader_class = Class.forName("dalvik.system.PathClassLoader"); 26 Constructor<?> ctor = 27 class_loader_class.getConstructor(String.class, ClassLoader.class); 28 /* on Dalvik, this is a DexFile; otherwise, it's null */ 29 return (ClassLoader) ctor.newInstance(location + "/" + TEST_NAME + "-ex.jar", 30 Main.class.getClassLoader()); 31 } catch (ClassNotFoundException e) { 32 // Running on RI. Use URLClassLoader. 33 return new java.net.URLClassLoader( 34 new java.net.URL[] { new java.net.URL("file://" + location + "/classes-ex/") }); 35 } 36 } 37 main(String[] args)38 public static void main(String[] args) throws Exception { 39 ClassLoader new_loader = getClassLoaderFor(System.getenv("DEX_LOCATION")); 40 Class<?> testClass = Class.forName("Test", true, new_loader); 41 Method testMain = testClass.getMethod("$noinline$main"); 42 testMain.invoke(null); 43 } 44 } 45