harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stepan Mishura" <stepan.mish...@gmail.com>
Subject Re: [classlib][swing] compatibility: j.s.text.GapContent.replace() behaviour
Date Fri, 03 Nov 2006 06:42:42 GMT
On 11/2/06, Ivanov, Alexey A wrote:
>
> 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.
>
> 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?



Hi Alexey,

I'm not quite convinced by your evaluation (I'm not an expert in Swing API
so I may be wrong). My experiments with GapContent showed that Harmony
initially created different object then RI, for example, if you create an
object with GapContent() constructor, Harmony will return start==0 and
end==9 while RI will return start==1 and end==10. The next point that
confuses me that the spec. says about position as "logical position in the
storage"...and... "This is not the location in the underlying storage
array". So negative value for position may be considered as valid.

Thanks,
Stepan.

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
>



-- 
Stepan Mishura
Intel Middleware Products Division

------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message