changeset 8911:72f48622dc29

RT-40376: TextField and TextArea can throw NPE when text is null
author leifs
date Sat, 28 Mar 2015 14:52:07 -0700
parents dbe7a82d8055
children 96ee85199d13 c32419e617d8
files modules/controls/src/main/java/javafx/scene/control/TextInputControl.java modules/controls/src/test/java/javafx/scene/control/TextInputControlTest.java
diffstat 2 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/TextInputControl.java	Fri Mar 27 13:39:17 2015 -0400
+++ b/modules/controls/src/main/java/javafx/scene/control/TextInputControl.java	Sat Mar 28 14:52:07 2015 -0700
@@ -911,6 +911,7 @@
     public boolean deleteNextChar() {
         boolean failed = true;
         if (isEditable() && !isDisabled()) {
+            final int textLength = getLength();
             final String text = getText();
             final int dot = getCaretPosition();
             final int mark = getAnchor();
@@ -918,7 +919,7 @@
                 // there is a selection of text to remove
                 replaceSelection("");
                 failed = false;
-            } else if (text.length() > 0 && dot < text.length()) {
+            } else if (textLength > 0 && dot < textLength) {
                 // The caret is not at the end, so remove some characters.
                 // Typically you'd only be removing a single character, but
                 // in some cases you must remove two depending on the unicode
--- a/modules/controls/src/test/java/javafx/scene/control/TextInputControlTest.java	Fri Mar 27 13:39:17 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/control/TextInputControlTest.java	Sat Mar 28 14:52:07 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1779,6 +1779,12 @@
         assertEquals("", textInput.getText());
     }
 
+    @Test public void test_rt40376_delete_next_when_text_is_null() {
+        textInput.setText(null);
+        textInput.deleteNextChar();
+    }
+
+
     // TODO tests for Content firing event notification properly
 
     // TODO tests for Content not allowing illegal characters