diff options
author | Thomas Watson | 2019-12-12 17:40:52 +0000 |
---|---|---|
committer | Thomas Watson | 2019-12-12 17:42:54 +0000 |
commit | 935bda5aaf2c2a0a0e0faa0f3c9f88ef2acd81c0 (patch) | |
tree | 0f1978b827981fe0837e9c2ea4cebd3f8d514b5e | |
parent | 851d2141f0396f67d96819d94a4a7a156c8ccb5d (diff) | |
download | rt.equinox.framework-935bda5aaf2c2a0a0e0faa0f3c9f88ef2acd81c0.tar.gz rt.equinox.framework-935bda5aaf2c2a0a0e0faa0f3c9f88ef2acd81c0.tar.xz rt.equinox.framework-935bda5aaf2c2a0a0e0faa0f3c9f88ef2acd81c0.zip |
Bug 552573 - getModule can throw BundleException
Change-Id: Idd39be6c8bd361fcb9f8c6a2e70d9a1f2596aac4
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
4 files changed, 36 insertions, 18 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java index 147b6067c..0fbb69861 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java @@ -104,11 +104,11 @@ public class ConnectTests extends AbstractBundleTests { } @Override - public Optional<ConnectModule> getModule(String location) { + public Optional<ConnectModule> getModule(String location) throws BundleException { getModuleCalled.add(location); ConnectModule m = modules.get(location); - if (m == ILLEGAL_STATE_EXCEPTION) { - throw new IllegalStateException(); + if (m == BUNDLE_EXCEPTION) { + throw new BundleException("Test fail install with getModule"); } return Optional.ofNullable(m); } @@ -301,7 +301,7 @@ public class ConnectTests extends AbstractBundleTests { } - static final TestConnectModule ILLEGAL_STATE_EXCEPTION = new TestConnectModule(null); + static final TestConnectModule BUNDLE_EXCEPTION = new TestConnectModule(null); public void testConnectFactoryNoModules() { TestCountingConnectFramework connectFactory = new TestCountingConnectFramework(); @@ -449,7 +449,7 @@ public class ConnectTests extends AbstractBundleTests { }); connectFactory.setModule("b.2", null); - connectFactory.setModule("b.3", ILLEGAL_STATE_EXCEPTION); + connectFactory.setModule("b.3", BUNDLE_EXCEPTION); doTestConnect(connectFactory, new HashMap<>(), (f) -> { try { f.init(); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectHookConfigurator.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectHookConfigurator.java index 2f4aa4fa1..bbee6b5df 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectHookConfigurator.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/connect/ConnectHookConfigurator.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.osgi.internal.connect; +import static org.eclipse.osgi.internal.framework.EquinoxContainer.sneakyThrow; + import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; @@ -54,7 +56,15 @@ public class ConnectHookConfigurator implements HookConfigurator { hookRegistry.addStorageHookFactory(new StorageHookFactory<Object, Object, StorageHook<Object, Object>>() { @Override protected StorageHook<Object, Object> createStorageHook(Generation generation) { - final ConnectModule m = connectModules.getConnectModule(generation.getBundleInfo().getLocation()); + ConnectModule tmp = null; + try { + tmp = connectModules.getConnectModule(generation.getBundleInfo().getLocation()); + } catch (IllegalStateException e) { + if (!(e.getCause() instanceof BundleException)) { + throw e; + } + } + final ConnectModule m = tmp; return new StorageHook<Object, Object>(generation, this.getClass()) { boolean hasModule = false; @@ -104,9 +114,15 @@ public class ConnectHookConfigurator implements HookConfigurator { if (location == null) { location = module.getLocation(); } - ConnectModule m = connectModules.getConnectModule(location); - if (m != null) { - return ConnectInputStream.URL_CONNECTION_INSTANCE; + try { + ConnectModule m = connectModules.getConnectModule(location); + if (m != null) { + return ConnectInputStream.URL_CONNECTION_INSTANCE; + } + } catch (IllegalStateException e) { + if (e.getCause() instanceof BundleException) { + sneakyThrow(e.getCause()); + } } return null; } @@ -162,9 +178,4 @@ public class ConnectHookConfigurator implements HookConfigurator { } }); } - - @SuppressWarnings("unchecked") - public static <E extends Throwable> void sneakyThrow(Throwable e) throws E { - throw (E) e; - } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java index 33a620458..d5e64c28b 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java @@ -374,6 +374,7 @@ public class EquinoxContainer implements ThreadFactory, Runnable { this.connectFramework = connectFramework; } + @SuppressWarnings("unused") public ConnectModule getConnectModule(String location) { if (connectFramework == null) { return null; @@ -381,8 +382,8 @@ public class EquinoxContainer implements ThreadFactory, Runnable { ConnectModule result = connectModules.computeIfAbsent(location, (l) -> { try { return connectFramework.getModule(location).orElse(NULL_MODULE); - } catch (IllegalStateException e) { - return NULL_MODULE; + } catch (BundleException e) { + throw new IllegalStateException(e); } }); return result == NULL_MODULE ? null : result; @@ -392,4 +393,9 @@ public class EquinoxContainer implements ThreadFactory, Runnable { return connectFramework; } } + + @SuppressWarnings("unchecked") + public static <E extends Throwable> void sneakyThrow(Throwable e) throws E { + throw (E) e; + } } diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFramework.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFramework.java index a1f4f0adc..3423d303c 100644 --- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFramework.java +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/framework/connect/ConnectFramework.java @@ -20,6 +20,7 @@ import java.util.Map; import java.util.Optional; import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleException; import org.osgi.framework.Constants; import org.osgi.framework.launch.Framework; @@ -66,9 +67,9 @@ public interface ConnectFramework { * * @param location the bundle location used to install a bundle * @return the connect module for the specified bundle location - * @throws IllegalStateException if the location cannot be handled + * @throws BundleException if the location cannot be handled */ - Optional<ConnectModule> getModule(String location); + Optional<ConnectModule> getModule(String location) throws BundleException; /** * Creates a new activator for this connect framework. A new activator is |