Community
Participate
Working Groups
A class cast exception happens in getAllMemberValuePairs due to the fact that the names array is an array of Strings and the comparator cast those elements to char[]. Additionally the insertion loop at the end can produce an AIOBE since the returned value from binarySearch is the negative insertion index and can therefore be less than -1. The correct code of the method should be as follows: // handle case of more methods than declared members char[][] names = new char[declaredLength][]; for (int i = 0; i < declaredLength; i++) names[i] = pairs[i].getName().toCharArray(); Comparator comparator = new Comparator() { public int compare(Object arg0, Object arg1) { return CharOperation.compareWith((char[]) arg0, (char[]) arg1); } }; Arrays.sort(names, comparator); IResolvedMemberValuePair[] allPairs = new IResolvedMemberValuePair[methodLength]; for (int i = 0; i < methodLength; i++) { int index = Arrays.binarySearch(names, methods[i].selector, comparator); allPairs[i] = index < 0 ? new ResolvedDefaultValuePair(methods[i], this.bindingResolver) : pairs[index]; } return allPairs; The are some additionally comments here: - the algorithm sorts the names not the pairs but the index is used at the end to access the pairs not the names. So this only works if all names are found since the picked pair might not match the name for which the binary search is used.
SO much for inheriting code. Dirk, do you have a case we can test against?
Not a public one. However making a test case is simple: - create an annotation with two default values and a non default value. - when sorted the default value should come after the non default value - reference the annotation only providing the non default value - resolve an IResolvedAnnotation from it - call getAllMemberValuePairs This should produce both exception.
Verified for 3.2 M5 using build I20060214-0010