RFR: 4138921: TextLayout handling of empty strings

Daniel Gredler dgredler at openjdk.org
Wed Sep 17 09:28:17 UTC 2025


On Wed, 3 Sep 2025 17:37:00 GMT, Phil Race <prr at 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...
>
> I have updated the CSR and marked it as reviewed. You may now move it to 'finalized'.

@prrace: In the [CSR](https://bugs.openjdk.org/browse/JDK-8366563) for this change, Joe said "Please consider whether or not a release note is warranted for the behavior change on which exception gets thrown." I think this is above my pay grade, no? Do I need to raise any flags with anyone about this?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/26947#issuecomment-3302117371


More information about the client-libs-dev mailing list