benjamin84 / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

NullPointerException from JTextComponentDriver#deleteText #154

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using version 1.0a1 of the FEST-Swing module.

  public void deleteText(JTextComponent textBox) {
    replaceText(textBox, null);
  }

The problem is that JTextComponentDriver#deleteText calls #replaceText with
null.

  public void replaceText(JTextComponent textBox, String text) {
    selectAll(textBox);
    if (isEmpty(text) && !isEmpty(textBox.getText())) {
        invokeAction(textBox, deletePrevCharAction);
        return;
    }
    enterText(textBox, text);
  }

In JTextComponentDriver#replaceText if the text is null (implicitly empty)
and the text box is also empty then the body of the if isn't executed,
i.e., the return isn't executed, so #enterText is called with null text.
Further down the call stack #enterText calls RobotFixture#enterText

  public void enterText(String text) {
    for (char character : text.toCharArray())
      type(character);
  }

RobotFixture#enterText tries to call toCharArray() on text, without
checking it for null.

A possible solution is:

  public void replaceText(JTextComponent textBox, String text) {
    selectAll(textBox);
    if (isEmpty(text)) {
      if (!isEmpty(textBox.getText())) {
        invokeAction(textBox, deletePrevCharAction);
      }
      return;
    }
    enterText(textBox, text);
  }

Another solution would be to modify JTextComponentDriver#deleteText to call
#replaceText with "" instead of null, but null seems to be acceptable as
JTextComponent#setText also accepts null and Robot#enterText shouldn't
concern itself with null, it should assume that it's called with "real"
text to enter.

Original issue reported on code.google.com by csaba.ju...@gmail.com on 10 Jun 2008 at 2:52

GoogleCodeExporter commented 9 years ago

Original comment by Alex.Rui...@gmail.com on 10 Jun 2008 at 8:58

GoogleCodeExporter commented 9 years ago
Hi Csabi,

This was already fixed in version 1.0a2 ( issue 123 )

Thanks!
-Alex

Original comment by Alex.Rui...@gmail.com on 12 Jun 2008 at 3:00

GoogleCodeExporter commented 9 years ago
Set the module as a label, instead of being part of the title.

Original comment by Alex.Rui...@gmail.com on 1 Dec 2008 at 2:02