changeset 6000:6ec6a557a2c4

RT-34959: [TextArea] TextArea with null text throws NPE on focus change
author leifs
date Wed, 18 Dec 2013 16:10:17 -0800
parents a6dbe9cc05a0
children c7848c7b7ae7
files modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/Utils.java
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java	Thu Dec 19 12:19:03 2013 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextAreaBehavior.java	Wed Dec 18 16:10:17 2013 -0800
@@ -171,7 +171,7 @@
                         double w = bounds.getWidth();
                         double h = bounds.getHeight();
                         Affine3D trans = TextFieldBehavior.calculateNodeToSceneTransform(textArea);
-                        String text = textArea.getText();
+                        String text = textArea.textProperty().getValueSafe();
 
                         // we need to display native text input component on the place where JFX component is drawn
                         // all parameters needed to do that are passed to native impl. here
@@ -272,7 +272,7 @@
         int start = selection.getStart();
         int end = selection.getEnd();
 
-        getUndoManager().addChange(start, textArea.getText().substring(start, end), "\n", false);
+        getUndoManager().addChange(start, textArea.textProperty().getValueSafe().substring(start, end), "\n", false);
         textArea.replaceSelection("\n");
     }
 
@@ -282,7 +282,7 @@
         int start = selection.getStart();
         int end = selection.getEnd();
 
-        getUndoManager().addChange(start, textArea.getText().substring(start, end), "\t", false);
+        getUndoManager().addChange(start, textArea.textProperty().getValueSafe().substring(start, end), "\t", false);
         textArea.replaceSelection("\t");
     }
 
@@ -338,7 +338,7 @@
             // if the primary button was pressed
             if (e.getButton() == MouseButton.PRIMARY && !(e.isMiddleButtonDown() || e.isSecondaryButtonDown())) {
                 HitInfo hit = skin.getIndex(e);
-                int i = com.sun.javafx.scene.control.skin.Utils.getHitInsertionIndex(hit, textArea.getText());
+                int i = com.sun.javafx.scene.control.skin.Utils.getHitInsertionIndex(hit, textArea.textProperty().getValueSafe());
 //                 int i = skin.getInsertionPoint(e.getX(), e.getY());
                 final int anchor = textArea.getAnchor();
                 final int caretPosition = textArea.getCaretPosition();
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/Utils.java	Thu Dec 19 12:19:03 2013 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/Utils.java	Wed Dec 18 16:10:17 2013 -0800
@@ -745,7 +745,7 @@
     private static BreakIterator charIterator = null;
     public static int getHitInsertionIndex(HitInfo hit, String text) {
         int charIndex = hit.getCharIndex();
-        if (!hit.isLeading()) {
+        if (text != null && !hit.isLeading()) {
             if (charIterator == null) {
                 charIterator = BreakIterator.getCharacterInstance();
             }