summaryrefslogtreecommitdiffstats
path: root/tests/068-classloader
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 18:28:14 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 18:28:14 -0800
commitf72d5de56a522ac3be03873bdde26f23a5eeeb3c (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /tests/068-classloader
parent31e30105703263782efd450d356cd67ea01af3b7 (diff)
downloadandroid_dalvik-f72d5de56a522ac3be03873bdde26f23a5eeeb3c.tar.gz
android_dalvik-f72d5de56a522ac3be03873bdde26f23a5eeeb3c.tar.bz2
android_dalvik-f72d5de56a522ac3be03873bdde26f23a5eeeb3c.zip
auto import from //depot/cupcake/@135843
Diffstat (limited to 'tests/068-classloader')
-rw-r--r--tests/068-classloader/expected.txt10
-rw-r--r--tests/068-classloader/info.txt8
-rw-r--r--tests/068-classloader/src-ex/DoubledExtend.java21
-rw-r--r--tests/068-classloader/src-ex/DoubledImplement.java19
-rw-r--r--tests/068-classloader/src-ex/DoubledImplement2.java33
-rw-r--r--tests/068-classloader/src-ex/IfaceImpl.java22
-rw-r--r--tests/068-classloader/src-ex/IfaceSub.java20
-rw-r--r--tests/068-classloader/src-ex/Inaccessible1.java12
-rw-r--r--tests/068-classloader/src-ex/Inaccessible2.java11
-rw-r--r--tests/068-classloader/src-ex/Inaccessible3.java11
-rw-r--r--tests/068-classloader/src/Base.java17
-rw-r--r--tests/068-classloader/src/DoubledExtend.java21
-rw-r--r--tests/068-classloader/src/DoubledImplement.java19
-rw-r--r--tests/068-classloader/src/DoubledImplement2.java33
-rw-r--r--tests/068-classloader/src/FancyLoader.java210
-rw-r--r--tests/068-classloader/src/ICommon.java9
-rw-r--r--tests/068-classloader/src/ICommon2.java23
-rw-r--r--tests/068-classloader/src/IfaceSuper.java20
-rw-r--r--tests/068-classloader/src/InaccessibleBase.java8
-rw-r--r--tests/068-classloader/src/InaccessibleInterface.java8
-rw-r--r--tests/068-classloader/src/Main.java281
-rw-r--r--tests/068-classloader/src/SimpleBase.java9
-rw-r--r--tests/068-classloader/src/Useless.java4
23 files changed, 0 insertions, 829 deletions
diff --git a/tests/068-classloader/expected.txt b/tests/068-classloader/expected.txt
deleted file mode 100644
index 0ca886270..000000000
--- a/tests/068-classloader/expected.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-base: class DoubledImplement
-base2: class DoubledImplement2
-Got expected access exception #1
-Got expected CNFE/IAE #2
-Got expected CNFE/IAE #3
-Got expected LinkageError on DE
-Ctor: doubled implement, type 1
-DoubledImplement one
-Got LinkageError on DI (early)
-Got LinkageError on IDI (early)
diff --git a/tests/068-classloader/info.txt b/tests/068-classloader/info.txt
deleted file mode 100644
index 421e52a3b..000000000
--- a/tests/068-classloader/info.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-Class loaders allow code to "redefine" a given class, e.g. it's possible to
-have multiple classes called "com.android.Blah" loaded simultaneously. The
-classes are distinct and must be treated as such. This test exercises
-some situations in which a VM that only checks the UTF-8 signatures could
-mix things up.
-
-This also tests a couple of situations in which an IllegalAccessException
-is expected.
diff --git a/tests/068-classloader/src-ex/DoubledExtend.java b/tests/068-classloader/src-ex/DoubledExtend.java
deleted file mode 100644
index 17da2c28c..000000000
--- a/tests/068-classloader/src-ex/DoubledExtend.java
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Doubled sub-class, form #2.
- */
-public class DoubledExtend extends Base {
- public DoubledExtend() {
- //System.out.println("Ctor: doubled extend, type 2");
- }
-
- @Override
- public DoubledExtend getExtended() {
- //System.out.println("getExtended 2");
- return new DoubledExtend();
- }
-
- public String getStr() {
- return "DoubledExtend 2";
- }
-}
-
diff --git a/tests/068-classloader/src-ex/DoubledImplement.java b/tests/068-classloader/src-ex/DoubledImplement.java
deleted file mode 100644
index b479d8fc2..000000000
--- a/tests/068-classloader/src-ex/DoubledImplement.java
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Doubled sub-class, form #2.
- */
-public class DoubledImplement implements ICommon {
- public DoubledImplement() {
- System.out.println("Ctor: doubled implement, type 2");
- }
-
- public DoubledImplement getDoubledInstance() {
- return new DoubledImplement();
- }
-
- public void two() {
- System.out.println("DoubledImplement two");
- }
-}
-
diff --git a/tests/068-classloader/src-ex/DoubledImplement2.java b/tests/068-classloader/src-ex/DoubledImplement2.java
deleted file mode 100644
index 60e820f63..000000000
--- a/tests/068-classloader/src-ex/DoubledImplement2.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-/**
- * Another doubled sub-class, form #2.
- */
-public class DoubledImplement2 implements ICommon2 {
- public DoubledImplement2() {
- System.out.println("Ctor: doubled implement, type 2");
- }
-
- public DoubledImplement2 getDoubledInstance2() {
- return new DoubledImplement2();
- }
-
- public void two() {
- System.out.println("DoubledImplement2 two");
- }
-}
-
diff --git a/tests/068-classloader/src-ex/IfaceImpl.java b/tests/068-classloader/src-ex/IfaceImpl.java
deleted file mode 100644
index 94a3bb0c1..000000000
--- a/tests/068-classloader/src-ex/IfaceImpl.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2008 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 IfaceImpl implements IfaceSub {
- public DoubledImplement2 getDoubledInstance2() {
- return new DoubledImplement2();
- }
-}
-
diff --git a/tests/068-classloader/src-ex/IfaceSub.java b/tests/068-classloader/src-ex/IfaceSub.java
deleted file mode 100644
index cb932bbcd..000000000
--- a/tests/068-classloader/src-ex/IfaceSub.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (C) 2008 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 interface IfaceSub extends IfaceSuper {
- public DoubledImplement2 getDoubledInstance2();
-}
-
diff --git a/tests/068-classloader/src-ex/Inaccessible1.java b/tests/068-classloader/src-ex/Inaccessible1.java
deleted file mode 100644
index 7b28427ec..000000000
--- a/tests/068-classloader/src-ex/Inaccessible1.java
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Non-public class, inaccessible from Main. Note the constructor is
- * public.
- */
-class Inaccessible1 extends SimpleBase {
- public Inaccessible1() {
- System.out.println("--- inaccessible1");
- }
-}
-
diff --git a/tests/068-classloader/src-ex/Inaccessible2.java b/tests/068-classloader/src-ex/Inaccessible2.java
deleted file mode 100644
index b612bfa9b..000000000
--- a/tests/068-classloader/src-ex/Inaccessible2.java
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Public class that can't access its base.
- */
-public class Inaccessible2 extends InaccessibleBase {
- public Inaccessible2() {
- System.out.println("--- inaccessible2");
- }
-}
-
diff --git a/tests/068-classloader/src-ex/Inaccessible3.java b/tests/068-classloader/src-ex/Inaccessible3.java
deleted file mode 100644
index 75a01be1b..000000000
--- a/tests/068-classloader/src-ex/Inaccessible3.java
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Public class that can't access its interface.
- */
-public class Inaccessible3 implements InaccessibleInterface {
- public Inaccessible3() {
- System.out.println("--- inaccessible3");
- }
-}
-
diff --git a/tests/068-classloader/src/Base.java b/tests/068-classloader/src/Base.java
deleted file mode 100644
index 37bc1f283..000000000
--- a/tests/068-classloader/src/Base.java
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Common base class.
- */
-public class Base {
- public Base() {}
-
- public DoubledExtend getExtended() {
- return new DoubledExtend();
- }
-
- public static String doStuff(DoubledExtend dt) {
- return dt.getStr();
- }
-}
-
diff --git a/tests/068-classloader/src/DoubledExtend.java b/tests/068-classloader/src/DoubledExtend.java
deleted file mode 100644
index 44c2bce62..000000000
--- a/tests/068-classloader/src/DoubledExtend.java
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Doubled sub-class, form #1.
- */
-public class DoubledExtend extends Base {
- public DoubledExtend() {
- //System.out.println("Ctor: doubled extend, type 1");
- }
-
- @Override
- public DoubledExtend getExtended() {
- System.out.println("getExtended 1");
- return new DoubledExtend();
- }
-
- public String getStr() {
- return "DoubledExtend 1";
- }
-}
-
diff --git a/tests/068-classloader/src/DoubledImplement.java b/tests/068-classloader/src/DoubledImplement.java
deleted file mode 100644
index 5568a4382..000000000
--- a/tests/068-classloader/src/DoubledImplement.java
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Doubled sub-class, form #1.
- */
-class DoubledImplement implements ICommon {
- public DoubledImplement() {
- System.out.println("Ctor: doubled implement, type 1");
- }
-
- public DoubledImplement getDoubledInstance() {
- return new DoubledImplement();
- }
-
- public void one() {
- System.out.println("DoubledImplement one");
- }
-}
-
diff --git a/tests/068-classloader/src/DoubledImplement2.java b/tests/068-classloader/src/DoubledImplement2.java
deleted file mode 100644
index 5e18315c4..000000000
--- a/tests/068-classloader/src/DoubledImplement2.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-/**
- * Another doubled sub-class, form #1.
- */
-public class DoubledImplement2 implements ICommon2 {
- public DoubledImplement2() {
- System.out.println("Ctor: doubled implement, type 1");
- }
-
- public DoubledImplement2 getDoubledInstance2() {
- return new DoubledImplement2();
- }
-
- public void one() {
- System.out.println("DoubledImplement2 one");
- }
-}
-
diff --git a/tests/068-classloader/src/FancyLoader.java b/tests/068-classloader/src/FancyLoader.java
deleted file mode 100644
index 491fd5c70..000000000
--- a/tests/068-classloader/src/FancyLoader.java
+++ /dev/null
@@ -1,210 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-
-/**
- * A class loader with atypical behavior: we try to load a private
- * class implementation before asking the system or boot loader. This
- * is used to create multiple classes with identical names in a single VM.
- *
- * If DexFile is available, we use that; if not, we assume we're not in
- * Dalvik and instantiate the class with defineClass().
- *
- * The location of the DEX files and class data is dependent upon the
- * test framework.
- */
-public class FancyLoader extends ClassLoader {
- /* this is where the "alternate" .class files live */
- static final String CLASS_PATH = "classes-ex/";
-
- /* this is the "alternate" DEX/Jar file */
- static final String DEX_FILE = "test-ex.jar";
-
- /* on Dalvik, this is a DexFile; otherwise, it's null */
- private Class mDexClass;
-
- /**
- * Construct FancyLoader, grabbing a reference to the DexFile class
- * if we're running under Dalvik.
- */
- public FancyLoader(ClassLoader parent) {
- super(parent);
-
- try {
- mDexClass = parent.loadClass("dalvik/system/DexFile");
- } catch (ClassNotFoundException cnfe) {
- // ignore -- not running Dalvik
- }
- }
-
- /**
- * Finds the class with the specified binary name.
- *
- * We search for a file in CLASS_PATH or pull an entry from DEX_FILE.
- * If we don't find a match, we throw an exception.
- */
- protected Class<?> findClass(String name) throws ClassNotFoundException
- {
- if (mDexClass != null) {
- return findClassDalvik(name);
- } else {
- return findClassNonDalvik(name);
- }
- }
-
- /**
- * Finds the class with the specified binary name, from a DEX file.
- */
- private Class<?> findClassDalvik(String name)
- throws ClassNotFoundException {
-
- Constructor ctor;
- Object dexFile;
-
- /*
- * Construct a DexFile object through reflection.
- */
- try {
- ctor = mDexClass.getConstructor(new Class[] { String.class });
- } catch (NoSuchMethodException nsme) {
- throw new ClassNotFoundException("getConstructor failed", nsme);
- }
-
- try {
- dexFile = ctor.newInstance(DEX_FILE);
- } catch (InstantiationException ie) {
- throw new ClassNotFoundException("newInstance failed", ie);
- } catch (IllegalAccessException iae) {
- throw new ClassNotFoundException("newInstance failed", iae);
- } catch (InvocationTargetException ite) {
- throw new ClassNotFoundException("newInstance failed", ite);
- }
-
- /*
- * Call DexFile.loadClass(String, ClassLoader).
- */
- Method meth;
-
- try {
- meth = mDexClass.getMethod("loadClass",
- new Class[] { String.class, ClassLoader.class });
- } catch (NoSuchMethodException nsme) {
- throw new ClassNotFoundException("getMethod failed", nsme);
- }
-
- try {
- meth.invoke(dexFile, name, this);
- } catch (IllegalAccessException iae) {
- throw new ClassNotFoundException("loadClass failed", iae);
- } catch (InvocationTargetException ite) {
- throw new ClassNotFoundException("loadClass failed",
- ite.getCause());
- }
-
- return null;
- }
-
- /**
- * Finds the class with the specified binary name, from .class files.
- */
- private Class<?> findClassNonDalvik(String name)
- throws ClassNotFoundException {
-
- String pathName = CLASS_PATH + name + ".class";
- //System.out.println("--- Fancy: looking for " + pathName);
-
- File path = new File(pathName);
- RandomAccessFile raf;
-
- try {
- raf = new RandomAccessFile(path, "r");
- } catch (FileNotFoundException fnfe) {
- throw new ClassNotFoundException("Not found: " + pathName);
- }
-
- /* read the entire file in */
- byte[] fileData;
- try {
- fileData = new byte[(int) raf.length()];
- raf.readFully(fileData);
- } catch (IOException ioe) {
- throw new ClassNotFoundException("Read error: " + pathName);
- } finally {
- try {
- raf.close();
- } catch (IOException ioe) {
- // drop
- }
- }
-
- /* create the class */
- //System.out.println("--- Fancy: defining " + name);
- try {
- return defineClass(name, fileData, 0, fileData.length);
- } catch (Throwable th) {
- throw new ClassNotFoundException("defineClass failed", th);
- }
- }
-
- /**
- * Load a class.
- *
- * Normally a class loader wouldn't override this, but we want our
- * version of the class to take precedence over an already-loaded
- * version.
- *
- * We still want the system classes (e.g. java.lang.Object) from the
- * bootstrap class loader.
- */
- protected Class<?> loadClass(String name, boolean resolve)
- throws ClassNotFoundException
- {
- Class res;
-
- /*
- * 1. Invoke findLoadedClass(String) to check if the class has
- * already been loaded.
- *
- * This doesn't change.
- */
- res = findLoadedClass(name);
- if (res != null) {
- System.out.println("FancyLoader.loadClass: "
- + name + " already loaded");
- if (resolve)
- resolveClass(res);
- return res;
- }
-
- /*
- * 3. Invoke the findClass(String) method to find the class.
- */
- try {
- res = findClass(name);
- if (resolve)
- resolveClass(res);
- }
- catch (ClassNotFoundException e) {
- // we couldn't find it, so eat the exception and keep going
- }
-
- /*
- * 2. Invoke the loadClass method on the parent class loader. If
- * the parent loader is null the class loader built-in to the
- * virtual machine is used, instead.
- *
- * (Since we're not in java.lang, we can't actually invoke the
- * parent's loadClass() method, but we passed our parent to the
- * super-class which can take care of it for us.)
- */
- res = super.loadClass(name, resolve); // returns class or throws
- return res;
- }
-}
-
diff --git a/tests/068-classloader/src/ICommon.java b/tests/068-classloader/src/ICommon.java
deleted file mode 100644
index 4eac9be1a..000000000
--- a/tests/068-classloader/src/ICommon.java
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Common interface.
- */
-public interface ICommon {
- public DoubledImplement getDoubledInstance();
-}
-
diff --git a/tests/068-classloader/src/ICommon2.java b/tests/068-classloader/src/ICommon2.java
deleted file mode 100644
index 13b2c2310..000000000
--- a/tests/068-classloader/src/ICommon2.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-/**
- * Common interface.
- */
-public interface ICommon2 {
- public DoubledImplement2 getDoubledInstance2();
-}
-
diff --git a/tests/068-classloader/src/IfaceSuper.java b/tests/068-classloader/src/IfaceSuper.java
deleted file mode 100644
index f01963a29..000000000
--- a/tests/068-classloader/src/IfaceSuper.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (C) 2008 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 interface IfaceSuper {
- public DoubledImplement2 getDoubledInstance2();
-}
-
diff --git a/tests/068-classloader/src/InaccessibleBase.java b/tests/068-classloader/src/InaccessibleBase.java
deleted file mode 100644
index d43ea006c..000000000
--- a/tests/068-classloader/src/InaccessibleBase.java
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Non-public base class, inaccessible from alternate class loader.
- */
-class InaccessibleBase {
-}
-
diff --git a/tests/068-classloader/src/InaccessibleInterface.java b/tests/068-classloader/src/InaccessibleInterface.java
deleted file mode 100644
index 6df7501c2..000000000
--- a/tests/068-classloader/src/InaccessibleInterface.java
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Non-public interface class, inaccessible from alternate class loader.
- */
-interface InaccessibleInterface {
-}
-
diff --git a/tests/068-classloader/src/Main.java b/tests/068-classloader/src/Main.java
deleted file mode 100644
index f8698be19..000000000
--- a/tests/068-classloader/src/Main.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-/**
- * Class loader test.
- */
-public class Main {
- /**
- * Main entry point.
- */
- public static void main(String[] args) {
- FancyLoader loader;
-
- loader = new FancyLoader(ClassLoader.getSystemClassLoader());
-
- /*
- * This statement has no effect on this program, but it can
- * change the point where a LinkageException is thrown in
- * testImplement(). When this is present the "reference
- * implementation" throws an exception from Class.newInstance(),
- * when it's absent the exception is deferred until the first time
- * we call a method that isn't actually implemented.
- *
- * This isn't the class that fails -- it's a class with the same
- * name in the "fancy" class loader -- but the VM thinks it has a
- * reference to one of these; presumably the difference is that
- * without this the VM finds itself holding a reference to an
- * instance of an uninitialized class.
- */
- System.out.println("base: " + DoubledImplement.class);
- System.out.println("base2: " + DoubledImplement2.class);
-
- /*
- * Run tests.
- */
- testAccess1(loader);
- testAccess2(loader);
- testAccess3(loader);
-
- testExtend(loader);
- testImplement(loader);
- testIfaceImplement(loader);
- }
-
- /**
- * See if we can load a class that isn't public to us. We should be
- * able to load it but not instantiate it.
- */
- static void testAccess1(ClassLoader loader) {
- Class altClass;
-
- try {
- altClass = loader.loadClass("Inaccessible1");
- } catch (ClassNotFoundException cnfe) {
- System.err.println("loadClass failed");
- cnfe.printStackTrace();
- return;
- }
-
- /* instantiate */
- Object obj;
- try {
- obj = altClass.newInstance();
- System.err.println("ERROR: Inaccessible1 was accessible");
- } catch (InstantiationException ie) {
- System.err.println("newInstance failed: " + ie);
- return;
- } catch (IllegalAccessException iae) {
- System.out.println("Got expected access exception #1");
- //System.out.println("+++ " + iae);
- return;
- }
- }
-
- /**
- * See if we can load a class whose base class is not accessible to it
- * (though the base *is* accessible to us).
- */
- static void testAccess2(ClassLoader loader) {
- Class altClass;
-
- try {
- altClass = loader.loadClass("Inaccessible2");
- System.err.println("ERROR: Inaccessible2 was accessible");
- } catch (ClassNotFoundException cnfe) {
- Throwable cause = cnfe.getCause();
- if (cause instanceof IllegalAccessError) {
- System.out.println("Got expected CNFE/IAE #2");
- } else {
- System.err.println("Got unexpected CNFE/IAE #2");
- cnfe.printStackTrace();
- }
- }
- }
-
- /**
- * See if we can load a class with an inaccessible interface.
- */
- static void testAccess3(ClassLoader loader) {
- Class altClass;
-
- try {
- altClass = loader.loadClass("Inaccessible3");
- System.err.println("ERROR: Inaccessible3 was accessible");
- } catch (ClassNotFoundException cnfe) {
- Throwable cause = cnfe.getCause();
- if (cause instanceof IllegalAccessError) {
- System.out.println("Got expected CNFE/IAE #3");
- } else {
- System.err.println("Got unexpected CNFE/IAE #3");
- cnfe.printStackTrace();
- }
- }
- }
-
- /**
- * Test a doubled class that extends the base class.
- */
- static void testExtend(ClassLoader loader) {
- Class doubledExtendClass;
- Object obj;
-
- /* get the "alternate" version of DoubledExtend */
- try {
- doubledExtendClass = loader.loadClass("DoubledExtend");
- //System.out.println("+++ DoubledExtend is " + doubledExtendClass
- // + " in " + doubledExtendClass.getClassLoader());
- } catch (ClassNotFoundException cnfe) {
- System.err.println("loadClass failed: " + cnfe);
- return;
- }
-
- /* instantiate */
- try {
- obj = doubledExtendClass.newInstance();
- } catch (InstantiationException ie) {
- System.err.println("newInstance failed: " + ie);
- return;
- } catch (IllegalAccessException iae) {
- System.err.println("newInstance failed: " + iae);
- return;
- } catch (LinkageError le) {
- System.out.println("Got expected LinkageError on DE");
- return;
- }
-
- /* use the base class reference to get a CL-specific instance */
- Base baseRef = (Base) obj;
- DoubledExtend de = baseRef.getExtended();
-
- /* try to call through it */
- try {
- String result;
-
- result = Base.doStuff(de);
- System.err.println("ERROR: did not get LinkageError on DE");
- System.err.println("(result=" + result + ")");
- } catch (LinkageError le) {
- System.out.println("Got expected LinkageError on DE");
- return;
- }
- }
-
- /**
- * Test a doubled class that implements a common interface.
- */
- static void testImplement(ClassLoader loader) {
- Class doubledImplementClass;
- Object obj;
-
- useImplement(new DoubledImplement(), true);
-
- /* get the "alternate" version of DoubledImplement */
- try {
- doubledImplementClass = loader.loadClass("DoubledImplement");
- } catch (ClassNotFoundException cnfe) {
- System.err.println("loadClass failed: " + cnfe);
- return;
- }
-
- /* instantiate */
- try {
- obj = doubledImplementClass.newInstance();
- } catch (InstantiationException ie) {
- System.err.println("newInstance failed: " + ie);
- return;
- } catch (IllegalAccessException iae) {
- System.err.println("newInstance failed: " + iae);
- return;
- } catch (LinkageError le) {
- System.out.println("Got LinkageError on DI (early)");
- return;
- }
-
- /* if we lived this long, try to do something with it */
- ICommon icommon = (ICommon) obj;
- useImplement(icommon.getDoubledInstance(), false);
- }
-
- /**
- * Do something with a DoubledImplement instance.
- */
- static void useImplement(DoubledImplement di, boolean isOne) {
- //System.out.println("useObject: " + di.toString() + " -- "
- // + di.getClass().getClassLoader());
- try {
- di.one();
- if (!isOne) {
- System.err.println("ERROR: did not get LinkageError on DI");
- }
- } catch (LinkageError le) {
- if (!isOne) {
- System.out.println("Got LinkageError on DI (late)");
- } else {
- throw le;
- }
- }
- }
-
-
- /**
- * Test a class that implements an interface with a super-interface
- * that refers to a doubled class.
- */
- static void testIfaceImplement(ClassLoader loader) {
- Class ifaceImplClass;
- Object obj;
-
- /*
- * Create an instance of IfaceImpl. We also pull in
- * DoubledImplement2 from the other class loader; without this
- * we don't fail in some implementations.
- */
- try {
- ifaceImplClass = loader.loadClass("IfaceImpl");
- ifaceImplClass = loader.loadClass("DoubledImplement2");
- } catch (ClassNotFoundException cnfe) {
- System.err.println("loadClass failed: " + cnfe);
- return;
- }
-
- /* instantiate */
- try {
- obj = ifaceImplClass.newInstance();
- } catch (InstantiationException ie) {
- System.err.println("newInstance failed: " + ie);
- return;
- } catch (IllegalAccessException iae) {
- System.err.println("newInstance failed: " + iae);
- return;
- } catch (LinkageError le) {
- System.out.println("Got LinkageError on IDI (early)");
- //System.out.println(le);
- return;
- }
-
- /*
- * Without the pre-load of FancyLoader->DoubledImplement2, some
- * implementations will happily execute through this part. "obj"
- * comes from FancyLoader, but the di2 returned from ifaceSuper
- * comes from the application class loader.
- */
- IfaceSuper ifaceSuper = (IfaceSuper) obj;
- DoubledImplement2 di2 = ifaceSuper.getDoubledInstance2();
- di2.one();
- }
-}
-
diff --git a/tests/068-classloader/src/SimpleBase.java b/tests/068-classloader/src/SimpleBase.java
deleted file mode 100644
index 5e1fb5aa3..000000000
--- a/tests/068-classloader/src/SimpleBase.java
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2008 The Android Open Source Project
-
-/**
- * Simple, public base class.
- */
-public class SimpleBase {
- public SimpleBase() {}
-}
-
diff --git a/tests/068-classloader/src/Useless.java b/tests/068-classloader/src/Useless.java
deleted file mode 100644
index f51d9a8f0..000000000
--- a/tests/068-classloader/src/Useless.java
+++ /dev/null
@@ -1,4 +0,0 @@
-
-public class Useless implements ICommon {
- public DoubledImplement getDoubledInstance() { return null; }
-}