RFR: 8335587: TextInputControl: Binding prompt text that contains linebreak causes exception

Andy Goryachev angorya at openjdk.org
Tue Feb 4 16:04:19 UTC 2025


On Tue, 4 Feb 2025 15:13:31 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:

>> When binding the promptTextProperty of a TextInputControl (TextField or TextArea) to a text that contains linebreaks/newlines ("\n") the "bind" call causes a RuntimeException to be thrown, the solution to it is to unbind before calling the set(txt) method to set the new value for the property.
>> Also added tests to test this new fix
>
> In my opinion, both the original implementation, as well as the proposed fix, are defective.
> 
> The implementation seems to try to enforce the (undocumented) invariant that the prompt text cannot contain line breaks. If that is indeed a sensible invariant, then the property should reject any attempt to set an invalid value by throwing an exception. Silently changing the property value is unexpected for developers.
> 
> However, it doesn't seem to me that this is a sensible invariant. `TextFieldSkin` and `TextAreaSkin` render the prompt text with a `Text` node, which doesn't have a single-line restriction. Simply not doing anything to the prompt text would be a good choice. Another good choice would be to clean up the prompt text where it is used (i.e. in `TextFieldSkin` and `TextAreaSkin`). We already do this in other places, for example in `LabeledSkinBase::getCleanText`.

@mstr2 you bring a good point: the behavior (removing newlines) is undocumented, and it should be.

I propose to do this in a separate issue, more specifically in https://bugs.openjdk.org/browse/JDK-8335547 which intends to remove the filtering for `TextArea` since that controls is capable of displaying multi-line prompts (and `TextField`/`PasswordField` are not)

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

PR Comment: https://git.openjdk.org/jfx/pull/1694#issuecomment-2634407246


More information about the openjfx-dev mailing list