harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Petrenko" <alexey.a.petre...@gmail.com>
Subject Re: [classlib][swing] compatibility: j.s.text.GapContent.replace() behaviour
Date Thu, 02 Nov 2006 12:46:57 GMT
I'll take care of 1975.

SY, Alexey

2006/11/2, Oleg Khaschansky <oleg.v.khaschansky@gmail.com>:
> +1. Silently doing nothing if invalid parameters are passed seems to
> me a right behavior in this case.
>
> Will someone apply changes to GapContent from the harmony-1975.patch
> or we need to make a separate patch for this?
>
> On 11/2/06, Alexey Petrenko <alexey.a.petrenko@gmail.com> wrote:
> > 2006/11/2, Ivanov, Alexey A <alexey.a.ivanov@intel.com>:
> > > Hi all,
> > >
> > > I've started fixing HARMONY-1809. To remove throws clause from the
> > > declaration of replace method, as it was proposed by Oleg in
> > > HARMONY-1975, I placed removeItems() and insertItems() calls into
> > > try-catch block. This would work OK for any valid arguments.
> > >
> > > I was going to handle invalid arguments by making adjustments so that
> > > the following removeItems() and insertItems() will not throw the
> > > exception. After I wrote several tests, I faced strange behaviour of RI
> > > with regards to invalid arguments to replace.
> > >
> > > (The Javadoc say nothing about which valid ranges for replace()
> > > parameters as well as any exceptions.)
> > >
> > > RI accepts invalid arguments but the result differs from what I'd
> > > expect.
> > > For example, if the content has "text" in it, I'd expect that
> > > content.replace(-2, 4, null, 0) would give "xt" as the result. I mean
> > > the invalid start position is adjusted to 0, and the length of remove is
> > > adjusted to be 2 accordingly. But this is not the case. As the result of
> > > this call, all characters are removed leaving "" in the content.
> > >
> > > Moreover the content object becomes unusable after that:
> > > content.insertString(0, "1") throws ArrayIndexOutOfBoundsException.
> > >
> > > Similarly if number of characters to be removed is greater than the
> > > length of the content (content.replace(2, 4, null, 0) with "text" in
> > > it), the object will throw ArrayIndexOutOfBoundsException when doing
> > > insertString.
> > >
> > >
> > > Considering the fact that GapContent is pretty low-level class in text
> > > representation model and that it is protected, I think that Harmony
> > > implementation can silently ignore BadLocationException possible thrown
> > > from insertItems() and removeItems(). Taking into account erroneous
> > > behaviour of RI's replace, we can do that until an application is
> > > broken.
> > +1 for this solution.
> >
> > SY, Alexey
> >
> > > As another option, we can throw an Error from catch block to make
> > > application which depends on implementation of replace() fast-fail.
> > >
> > >
> > > Any objections, comments, opinions?
> > >
> > > Thanks,
> > > Alexey.
> > >
> > >
> > > P.S. The related JIRA issues:
> > > https://issues.apache.org/jira/browse/HARMONY-1809
> > > https://issues.apache.org/jira/browse/HARMONY-1975
> > >
> > > GapContent Javadoc:
> > > http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/GapContent.html
> > > Description of GapContent.replace:
> > > http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/GapContent.html
> > > #replace(int,%20int,%20java.lang.Object,%20int)
> > >
> > >
> > > --
> > > Alexey A. Ivanov
> > > Intel Middleware Product Division
> > >
> >
>

Mime
View raw message