-
CSR
-
Resolution: Approved
-
P3
-
None
-
behavioral
-
low
-
-
Java API
-
SE
Summary
java.awt.font.TextLayout constructors now allow empty strings, and have updated exception handling specification and implementation.
Problem
Clients have to check whether a string is empty or not before passing it to the TextLayout constructors, because the constructors explicitly check for empty strings and throw an IllegalArgumentException if the string is empty. Furthermore, this limitation is not specified. This surprises developers, leads to bugs in applications when developers are not aware of this limitation, and creates unnecessary complexity in applications.
Additionally, the scenarios which might cause exceptions to be thrown from the TextLayout constructors are not all specified.
Finally, there is an inconsistency in the parameter validation of the TextLayout constructors: no constructor parameters are allowed to be null, and if they are null then an IllegalArgumentException is thrown -- except if a null FontRenderContext is provided, in which case a NullPointerException is eventually thrown (not explicitly, but because of a null dereference).
Solution
- Allow TextLayout to be constructed with empty strings.
- Document the existing exceptions thrown by the TextLayout constructors.
- Add explicit checks for null FontRenderContext instances, and throw IllegalArgumentException in such cases (mirroring existing behavior for all other constructor parameters).
Specification
public class java.awt.font.TextLayout
+ * @throws IllegalArgumentException if any of the parameters are null.
*/
public TextLayout(String string, Font font, FontRenderContext frc)
+ * @throws IllegalArgumentException if any of the parameters are null.
*/
public TextLayout(String string, Map<? extends Attribute,?> attributes,
FontRenderContext frc)
+ * @throws IllegalArgumentException if any of the parameters are null.
*/
public TextLayout(AttributedCharacterIterator text, FontRenderContext frc)
```
- csr of
-
JDK-4138921 TextLayout handling of empty strings
-
- Open
-