felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dan Gravell (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FELIX-3652) ArrayIndexOutOfBoundsException when trying to adapt() a stopped bundle
Date Mon, 03 Sep 2012 16:23:07 GMT

    [ https://issues.apache.org/jira/browse/FELIX-3652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13447339#comment-13447339
] 

Dan Gravell commented on FELIX-3652:
------------------------------------

Thanks. 

My view of this is that I'm doing something incorrect by re-using the old Bundle objects.
Therefore I've implemented my own change by storing the symbolic names of bundles (before
anything happens - I note this also requires use of adapt()) and then looking them up again
when I want to re-start the bundles. 

I assumed this was worth reporting as the behaviour seemed to diverge from the Javadoc.
                
> 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

Mime
View raw message