[ https://issues.apache.org/jira/browse/FELIX-3652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13447333#comment-13447333 ]
Richard S. Hall commented on FELIX-3652: ---------------------------------------- If you can get me to reproduce it, then I can look into directly. > ArrayIndexOutOfBoundsException when trying to adapt() a stopped bundle > ---------------------------------------------------------------------- > > Key: FELIX-3652 > URL: https://issues.apache.org/jira/browse/FELIX-3652 > Project: Felix > Issue Type: Bug > Components: Framework > Affects Versions: framework-4.0.2 > Reporter: Dan Gravell > Priority: Minor > > I have the following code block: > final Iterable<Bundle> startedBundles = [...] > for (Bundle bundle : startedBundles) { > try { > if(!FelixObrUtils.isFragment(bundle)) > sysBundle.getBundleContext().getBundle(bundle.getBundleId()).stop(); > } catch (BundleException e) { > LOG.error("Failed to stop " + bundle.getSymbolicName(), e); > } > } > resolver.deploy(0); > blockingRefreshBundles(null, sysBundle.getBundleContext()); > for (Bundle bundle : startedBundles) { > try { > if(!FelixObrUtils.isFragment(bundle)) > sysBundle.getBundleContext().getBundle(bundle.getBundleId()).start(); > } catch (BundleException e) { > LOG.error("Failed to restart " + bundle.getSymbolicName(), e); > } > } > blockingRefreshBundles() blocks until frameworkWiring.refreshBundles has > completed using a CountDownLatch and a FrameworkListener. > Pertinently, FelixObrUtils.isFragment looks like: > public static boolean isFragment(Bundle bundle) { > return (bundle.adapt(BundleRevision.class).getTypes() & > BundleRevision.TYPE_FRAGMENT) != 0; > } > Upon the second call to FelixObrUtils.isFragment I get: > java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 > at java.util.ArrayList.rangeCheck(ArrayList.java:571) > at java.util.ArrayList.get(ArrayList.java:349) > at org.apache.felix.framework.BundleImpl.adapt(BundleImpl.java:1046) > at > com.elsten.bliss.updater.FelixObrUtils.isFragment(FelixObrUtils.java:149) > at > com.elsten.bliss.updater.OnlineUpdater$2.doRun(OnlineUpdater.java:124) > at > com.elsten.util.CatchThrowableRunnable.run(CatchThrowableRunnable.java:23) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) > at java.lang.Thread.run(Thread.java:679) > Presumably this is because the bundle has been stopped, possibly updated and > refreshed in the meantime. > Maybe I should not be doing this on a stopped bundle, and I should be getting > a fresh view of the bundle, but shouldn't this be handled differently? AIOOBE > is not documented as an exception that may be thrown in the OSGi API. Knowing > how to handle this requires knowledge of BundleImpl's implementation > (m_revisions etc). -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira