From 7a9a138541a8114ccb55067d8639773d5c5997c5 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 5 Jan 2010 21:53:34 +0000 Subject: Bug 298894 - IllegalArgumentException can occur during PackagePermission check --- .../tests/securityadmin/SecurityManagerTests.java | 51 +++++++++++++++++++++- bundles/org.eclipse.osgi/META-INF/MANIFEST.MF | 2 +- .../osgi/internal/module/PermissionChecker.java | 4 +- .../osgi/internal/module/ResolverConstraint.java | 6 +-- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java index 040481056..0098a0e6e 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -320,6 +320,55 @@ public class SecurityManagerTests extends AbstractBundleTests { assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ } + public void testEnableSecurityManager05() throws BundleException { + File config = OSGiTestsActivator.getContext().getDataFile(getName()); //$NON-NLS-1$ + Properties configuration = new Properties(); + configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()); + configuration.put(Constants.FRAMEWORK_SECURITY, Framework.SECURITY_OSGI); + Equinox equinox = new Equinox(configuration); + try { + equinox.init(); + } catch (BundleException e) { + fail("Unexpected exception on init()", e); //$NON-NLS-1$ + } + + assertNotNull("SecurityManager is null", System.getSecurityManager()); //$NON-NLS-1$ + // should be in the STARTING state + assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState()); //$NON-NLS-1$ + + BundleContext systemContext = equinox.getBundleContext(); + assertNotNull("System context is null", systemContext); //$NON-NLS-1$ + // try installing a bundle to tests bug + String locationLinkA = installer.getBundleLocation("test.link.a"); //$NON-NLS-1$ + String locationLinkAClient = installer.getBundleLocation("test.link.a.client"); //$NON-NLS-1$ + + Bundle linkA = systemContext.installBundle(locationLinkA); + Bundle linkAClient = systemContext.installBundle(locationLinkAClient); + equinox.start(); + + try { + PackageAdmin pa = (PackageAdmin) systemContext.getService(systemContext.getServiceReference(PackageAdmin.class.getName())); + assertTrue(pa.resolveBundles(new Bundle[] {linkA, linkAClient})); + linkA.uninstall(); + linkAClient.uninstall(); + + linkA = systemContext.installBundle(locationLinkA); + linkAClient = systemContext.installBundle(locationLinkAClient); + assertTrue(pa.resolveBundles(new Bundle[] {linkA, linkAClient})); + } finally { + // put the framework back to the RESOLVED state + equinox.stop(); + + try { + equinox.waitForStop(10000); + } catch (InterruptedException e) { + fail("Unexpected interrupted exception", e); //$NON-NLS-1$ + } + } + assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ + assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ + } + public void testLocalization01() throws BundleException { // create/start/stop/start/stop test File config = OSGiTestsActivator.getContext().getDataFile("testLocalization01"); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF index 939b8e4e2..7696d37f9 100644 --- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF @@ -68,7 +68,7 @@ Bundle-Activator: org.eclipse.osgi.framework.internal.core.SystemBundleActivator Bundle-Description: %systemBundle Bundle-Copyright: %copyright Bundle-Vendor: %eclipse.org -Bundle-Version: 3.5.1.qualifier +Bundle-Version: 3.5.2.qualifier Bundle-Localization: systembundle Bundle-DocUrl: http://www.eclipse.org Eclipse-ExtensibleAPI: true diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/PermissionChecker.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/PermissionChecker.java index 0c9033ffa..4ef1b4197 100644 --- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/PermissionChecker.java +++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/PermissionChecker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -41,7 +41,7 @@ public class PermissionChecker { errorType = ResolverError.IMPORT_PACKAGE_PERMISSION; producer = context.getBundle(((ExportPackageDescription) bd).getExporter().getBundleId()); producerPermission = new PackagePermission(bd.getName(), PackagePermission.EXPORTONLY); - consumerPermission = new PackagePermission(vc.getName(), producer, PackagePermission.IMPORT); + consumerPermission = producer != null ? new PackagePermission(vc.getName(), producer, PackagePermission.IMPORT) : new PackagePermission(vc.getName(), PackagePermission.IMPORT); } else { boolean requireBundle = vc instanceof BundleSpecification; errorType = requireBundle ? ResolverError.REQUIRE_BUNDLE_PERMISSION : ResolverError.FRAGMENT_BUNDLE_PERMISSION; diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java index 49713ee0f..b692b1155 100644 --- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java +++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverConstraint.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. All rights reserved. This + * Copyright (c) 2005, 2010 IBM Corporation and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -42,9 +42,9 @@ public abstract class ResolverConstraint { // Same as VersionConstraint but does additinal permission checks boolean isSatisfiedBy(VersionSupplier vs) { - if (!bundle.getResolver().getPermissionChecker().checkPermission(constraint, vs.getBaseDescription())) + if (vs.getResolverBundle().isUninstalled() || !bundle.getResolver().getPermissionChecker().checkPermission(constraint, vs.getBaseDescription())) return false; - return vs.getSubstitute() == null && !vs.getResolverBundle().isUninstalled() && constraint.isSatisfiedBy(vs.getBaseDescription()); + return vs.getSubstitute() == null && constraint.isSatisfiedBy(vs.getBaseDescription()); } // returns the companion VersionConstraint object from the State -- cgit v1.2.1