I have encountered strange behaviour of aforementioned method. There is a legacy component that is used to display xml file contents, it works in java6, however when I switch to 1.7_10 it fails as end offset is out of view's bounds.
I have researched this problem a bit and found following method javax.swing.text.ParagraphView.findEdgeSpan(View, int, int, int, int)
This is method's code:
/**
* Binary search for the longest non-breakable fragment at the view edge.
*/
private float findEdgeSpan(View v, int axis, int fp, int p0, int p1) {
int len = p1 - p0;
if (len <= 1) {
// further fragmentation is not possible
return v.getMinimumSpan(axis);
} else {
int mid = p0 + len / 2;
boolean startEdge = mid > fp;
// initial view is breakable hence must support fragmentation
View f = startEdge ?
v.createFragment(fp, mid) : v.createFragment(mid, fp);
boolean breakable = f.getBreakWeight(
axis, 0, f.getMaximumSpan(axis)) > View.BadBreakWeight;
if (breakable == startEdge) {
p1 = mid;
} else {
p0 = mid;
}
return findEdgeSpan(f, axis, fp, p0, p1);
}
}
It creates view's fragment then runs on this fragment but offset boundaries are taken from outer view. And it may happen that bondaries passed to createFragment
are out of view f
boundaries.
Could someone explain if it is proper behaviour?
In javadoc for javax.swing.text.View.createFragment
:
Parameters:
p0 the starting offset >= 0. This should be a value greater or equal to the element starting offset and less than the element ending offset.
p1 the ending offset > p0. This should be a value less than or equal to the elements end offset and greater than the elements starting offset.
As I understand p1 should not be greater than view's endOffset, is not it?