Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2020-02-07 20:14:52 +0000
committerThomas Watson2020-02-07 20:14:52 +0000
commit4f46832028bc86417a8d71c8f053f71542c153f5 (patch)
treec7f9a3f25401543e73306156110e21cd45ccfef9
parent53cda2fec39d3a012525051b96af1155c9c7f07b (diff)
parentf849845222a1236328141fdde49ccb2a1e24c65b (diff)
downloadrt.equinox.framework-4f46832028bc86417a8d71c8f053f71542c153f5.tar.gz
rt.equinox.framework-4f46832028bc86417a8d71c8f053f71542c153f5.tar.xz
rt.equinox.framework-4f46832028bc86417a8d71c8f053f71542c153f5.zip
Merge branch 'master' into osgiR8
-rw-r--r--bundles/org.eclipse.osgi.tests/.classpath1
-rw-r--r--bundles/org.eclipse.osgi.tests/build.properties3
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/test.dynamic.privateimport/META-INF/MANIFEST.MF8
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/test.dynamic.privateimport/test/dynamic/privateimport/Activator.java29
-rwxr-xr-xbundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java45
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java24
6 files changed, 99 insertions, 11 deletions
diff --git a/bundles/org.eclipse.osgi.tests/.classpath b/bundles/org.eclipse.osgi.tests/.classpath
index dbab082d2..2d89fd740 100644
--- a/bundles/org.eclipse.osgi.tests/.classpath
+++ b/bundles/org.eclipse.osgi.tests/.classpath
@@ -128,6 +128,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 985449baa..91c0b2d8b 100644
--- a/bundles/org.eclipse.osgi.tests/build.properties
+++ b/bundles/org.eclipse.osgi.tests/build.properties
@@ -271,6 +271,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/
@@ -411,6 +413,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 a08fd393a..0889e2678 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
@@ -4157,6 +4157,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);

Back to the top