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

Thomas Schurins commented on FELIX-5131:
----------------------------------------

Thanks for looking at this.
I'm using the IBM jdk 1.6.0 (sic) coming with WebSphere. Here is the 
binarySearch method:
{code}
public static <T> int binarySearch(List<? extends T> list, T object,
                Comparator<? super T> comparator) {
        if (comparator == null) {
                return Collections.binarySearch(
                                (List<? extends Comparable<? super T>>) list, 
object);
        }
        if (!(list instanceof RandomAccess)) {
                ListIterator<? extends T> it = list.listIterator();
                while (it.hasNext()) {
                        int result;
                        if ((result = -comparator.compare(it.next(), object)) 
<= 0) {
                                if (result == 0) {
                                        return it.previousIndex();
                                }
                                return -it.previousIndex() - 1;
                        }
                }
                return -list.size() - 1;
        }

        int low = 0, mid = list.size(), high = mid - 1, result = -1;
        while (low <= high) {
                mid = (low + high) >> 1;
                if ((result = -comparator.compare(list.get(mid),object)) > 0) {
                        low = mid + 1;
                } else if (result == 0) {
                        return mid;
                } else {
                        high = mid - 1;
                }
        }
        return -mid - (result < 0 ? 1 : 2);
}
{code}



> UnsupportedOperationException when embedding felix in WebSphere
> ---------------------------------------------------------------
>
>                 Key: FELIX-5131
>                 URL: https://issues.apache.org/jira/browse/FELIX-5131
>             Project: Felix
>          Issue Type: Bug
>          Components: Framework, Resolver
>    Affects Versions: framework-5.2.0, resolver-1.6.0
>            Reporter: Thomas Schurins
>         Attachments: FELIX-5131.patch
>
>
> Hello, we are embedding the OSGi framework in our application (creating the 
> framework , managing its export packages, contolling the bundles &c.). This 
> works great in a lot of enviroments, but not on WebSphere (using the IBM 
> JDK): 
> {noformat}
> java.lang.UnsupportedOperationException
>       at 
> org.apache.felix.resolver.util.CopyOnWriteList.listIterator(CopyOnWriteList.java:218)
>       at java.util.Collections.binarySearch(Collections.java:1551)
>       at 
> org.apache.felix.framework.ResolveContextImpl.insertHostedCapability(ResolveContextImpl.java:103)
>       at org.apache.felix.resolver.Candidates.prepare(Candidates.java:934)
>       at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:233)
>       at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:159)
>       at 
> org.apache.felix.framework.StatefulResolver.resolve(StatefulResolver.java:431)
>       at 
> org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4109)
>       at org.apache.felix.framework.Felix.startBundle(Felix.java:2111)
>       at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1365)
>       at 
> org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
>       at java.lang.Thread.run(Thread.java:790)
> {noformat}
> The problem seems to be that in the IBM JDK, the Collections.binarySearch 
> method directly uses the listIterator of the list if it is not a RandomAccess 
> list (while the oracle JDK doesn't).
> A solution it to add the interface RandomAccess to the CopyOnWriteList class. 
> I've tested this locally and eveything runs fine.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to