On Wed, 3 Sep 2025 00:44:36 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:
>> `TextLayout` should deal more gracefully with zero length strings. Currently >> the exception listed below is the one that is thrown. >> >> `new TextLayout("", f, new FontRenderContext(null, false, false));` >> >>> Exception in thread "main" java.lang.IllegalArgumentException: Zero length >>> string passed to TextLayout constructor. >>> at java.lang.Throwable.<init>(Compiled Code) >>> at java.lang.Exception.<init>(Compiled Code) >>> at java.lang.RuntimeException.<init>(Compiled Code) >>> at java.lang.IllegalArgumentException.<init>(Compiled Code) >>> at java.awt.font.TextLayout.<init>(Compiled Code) >>> at test.main(Compiled Code) >> >> **REVIEWER NOTE:** Please check the empty-string `TextLayout` behavior >> documented in `TextLayoutConstructorTest` carefully; a badly-behaving empty >> `TextLayout` is probably worse than a `TextLayout` which doesn't allow empty >> strings... > > src/java.desktop/share/classes/java/awt/font/TextLayout.java line 516: > >> 514: >> 515: int start = text.getBeginIndex(); >> 516: int limit = text.getEndIndex(); > > Why do we call text.first() twice, on line 516 and in the loop init block? I'm not sure, I don't think it's necessary. The code has been this way since the first public commit, so there is no hint in the public git history. Should I remove it? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/26947#discussion_r2319077084