diff options
author | Thomas Watson | 2020-02-07 17:10:08 +0000 |
---|---|---|
committer | Thomas Watson | 2020-02-07 19:47:14 +0000 |
commit | f849845222a1236328141fdde49ccb2a1e24c65b (patch) | |
tree | 59ec45db7cd93013f0381f6a3139ba646ade56ad | |
parent | 45cc7f3c389fe4bc51505b898d02fbb076e58928 (diff) | |
download | rt.equinox.framework-f849845222a1236328141fdde49ccb2a1e24c65b.tar.gz rt.equinox.framework-f849845222a1236328141fdde49ccb2a1e24c65b.tar.xz rt.equinox.framework-f849845222a1236328141fdde49ccb2a1e24c65b.zip |
Bug 559926 - ClassNotFoundException thrown for previously defined
classes when dynamic import takes over
Change-Id: I7c5a786ac2de02353c058782e6867f272f88b8e2
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
6 files changed, 99 insertions, 11 deletions
diff --git a/bundles/org.eclipse.osgi.tests/.classpath b/bundles/org.eclipse.osgi.tests/.classpath index 2650588cc..cc895951b 100644 --- a/bundles/org.eclipse.osgi.tests/.classpath +++ b/bundles/org.eclipse.osgi.tests/.classpath @@ -127,6 +127,7 @@ <classpathentry kind="src" output="bundle_tests/test.protocol.handler.user" path="bundles_src/test.protocol.handler.user"/> <classpathentry kind="src" output="bundle_tests/test.bug471551" path="bundles_src/test.bug471551"/> <classpathentry kind="src" output="bundle_tests/test.dynamicimport" path="bundles_src/test.dynamicimport"/> + <classpathentry kind="src" output="bundle_tests/test.dynamic.privateimport" path="bundles_src/test.dynamic.privateimport"/> <classpathentry kind="src" output="bundle_tests/test.bug490902.a" path="bundles_src/test.bug490902.a"/> <classpathentry kind="src" output="bundle_tests/test.bug490902.b" path="bundles_src/test.bug490902.b"/> <classpathentry kind="src" output="bundle_tests/mrBundleInputBase" path="bundles_src/mrBundleInputBase"/> diff --git a/bundles/org.eclipse.osgi.tests/build.properties b/bundles/org.eclipse.osgi.tests/build.properties index b5f9ec757..0054cac41 100644 --- a/bundles/org.eclipse.osgi.tests/build.properties +++ b/bundles/org.eclipse.osgi.tests/build.properties @@ -269,6 +269,8 @@ source.bundle_tests/test.bug471551.jar = bundles_src/test.bug471551/ manifest.bundle_tests/test.bug471551.jar = META-INF/MANIFEST.MF source.bundle_tests/test.dynamicimport.jar = bundles_src/test.dynamicimport/ manifest.bundle_tests/test.dynamicimport.jar = META-INF/MANIFEST.MF +source.bundle_tests/test.dynamic.privateimport.jar = bundles_src/test.dynamic.privateimport/ +manifest.bundle_tests/test.dynamic.privateimport.jar = META-INF/MANIFEST.MF source.bundle_tests/test.bug490902.b.jar = bundles_src/test.bug490902.b/ manifest.bundle_tests/test.bug490902.b.jar = META-INF/MANIFEST.MF source.bundle_tests/test.bug490902.a.jar = bundles_src/test.bug490902.a/ @@ -408,6 +410,7 @@ jars.compile.order = bundle_tests/ext.framework.b.jar,\ bundle_tests/test.protocol.handler.user.jar,\ bundle_tests/test.bug471551.jar,\ bundle_tests/test.dynamicimport.jar,\ + bundle_tests/test.dynamic.privateimport.jar,\ bundle_tests/test.bug490902.b.jar,\ bundle_tests/test.bug490902.a.jar,\ bundle_tests/mrBundleInputBase.jar
\ No newline at end of file diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/test.dynamic.privateimport/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/test.dynamic.privateimport/META-INF/MANIFEST.MF new file mode 100644 index 000000000..7410d05c8 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/test.dynamic.privateimport/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: test.dynamic.privateimport +Bundle-SymbolicName: test.dynamic.privateimport +Bundle-Version: 1.0.0 +Bundle-Activator: test.dynamic.privateimport.Activator +Import-Package: org.osgi.framework +DynamicImport-Package: * diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/test.dynamic.privateimport/test/dynamic/privateimport/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/test.dynamic.privateimport/test/dynamic/privateimport/Activator.java new file mode 100644 index 000000000..5d4317528 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/test.dynamic.privateimport/test/dynamic/privateimport/Activator.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package test.dynamic.privateimport; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + public void start(BundleContext context) throws Exception { + System.out.println("Starting: " + context.getBundle()); + } + + public void stop(BundleContext context) throws Exception { + //nothing + } + +} diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index 19f819ff4..2a1f278be 100755 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -4158,6 +4158,51 @@ public class SystemBundleTests extends AbstractBundleTests { } } + public void testDynamicImportPrivatePackage() throws IOException { + File config = OSGiTestsActivator.getContext().getDataFile(getName()); //$NON-NLS-1$ + Map configuration = new HashMap(); + configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()); + Equinox equinox = null; + try { + equinox = new Equinox(configuration); + equinox.start(); + BundleContext bc = equinox.getBundleContext(); + + Bundle importer = bc.installBundle(installer.getBundleLocation("test.dynamic.privateimport")); + importer.start(); + + Map<String, String> exporter = new HashMap<>(); + exporter.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + exporter.put(Constants.BUNDLE_SYMBOLICNAME, getName() + ".exporter"); + exporter.put(Constants.EXPORT_PACKAGE, "test.dynamic.privateimport"); + File f1 = SystemBundleTests.createBundle(config, getName() + ".exporter", exporter); + Bundle exporterBundle = bc.installBundle("reference:file:///" + f1.getAbsolutePath()); //$NON-NLS-1$ + exporterBundle.start(); + + try { + importer.loadClass("test.dynamic.privateimport.DoesNotExist"); + } catch (ClassNotFoundException e) { + // expected + } + + importer.stop(); + importer.start(); + } catch (BundleException e) { + fail("Unexpected BundleException", e); + } finally { + try { + if (equinox != null) { + equinox.stop(); + equinox.waitForStop(1000); + } + } catch (BundleException e) { + fail("Failed to stop framework.", e); + } catch (InterruptedException e) { + fail("Failed to stop framework.", e); + } + } + } + // Note this is more of a performance test. It has a timeout that will cause it to // fail if it takes too long. public void testMassiveParallelInstallStart() { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java index 9bc6370e8..4db50392b 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2018 IBM Corporation and others. + * Copyright (c) 2004, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -414,24 +414,20 @@ public class BundleLoader extends ModuleLoader { * Finds the class for a bundle. This method is used for delegation by the bundle's classloader. */ public Class<?> findClass(String name) throws ClassNotFoundException { - return findClass(name, true); - } - Class<?> findClass(String name, boolean checkParent) throws ClassNotFoundException { - if (checkParent && parent != null && name.startsWith(JAVA_PACKAGE)) + if (parent != null && name.startsWith(JAVA_PACKAGE)) { // 1) if startsWith "java." delegate to parent and terminate search // we want to throw ClassNotFoundExceptions if a java.* class cannot be loaded from the parent. return parent.loadClass(name); - return findClassInternal(name, checkParent); - } + } - private Class<?> findClassInternal(String name, boolean checkParent) throws ClassNotFoundException { if (debug.DEBUG_LOADER) - Debug.println("BundleLoader[" + this + "].findClassInternal(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println("BundleLoader[" + this + "].findClass(" + name + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String pkgName = getPackageName(name); boolean bootDelegation = false; // follow the OSGi delegation model - if (checkParent && parent != null && container.isBootDelegationPackage(pkgName)) { + if (parent != null && container.isBootDelegationPackage(pkgName)) { // 2) if part of the bootdelegation list then delegate to parent and continue of failure try { return parent.loadClass(name); @@ -458,6 +454,11 @@ public class BundleLoader extends ModuleLoader { } // 3) found import source terminate search at the source result = source.loadClass(name); + if (result == null) { + // last ditch find loaded check in case something is reflectively + // calling defineClass on our loader. + result = getModuleClassLoader().publicFindLoaded(name); + } if (result != null) return result; throw new ClassNotFoundException(name + " cannot be found by " + this); //$NON-NLS-1$ @@ -503,7 +504,8 @@ public class BundleLoader extends ModuleLoader { return result; // hack to support backwards compatibility for bootdelegation // or last resort; do class context trick to work around VM bugs - if (parent != null && !bootDelegation && ((checkParent && container.getConfiguration().compatibilityBootDelegation) || isRequestFromVM())) { + if (parent != null && !bootDelegation + && ((container.getConfiguration().compatibilityBootDelegation) || isRequestFromVM())) { // we don't need to continue if a CNFE is thrown here. try { return parent.loadClass(name); |