[HtmlUnit] [htmlunit:bugs] #1964 NPE HtmlTextArea.removeFocus()
RBRi via HtmlUnit-develop <[email protected]>
| Newsgroups | gmane.comp.java.htmlunit.devel |
|---|---|
| Message-ID | </p/htmlunit/bugs/1964/c16135220608a34586314f1a3ceaf708af52cf22.bugs@htmlunit.p.sourceforge.net> |
fixed in SVN. Will inform via Twitter if a new snapshot is available. Thanks for this report and sorry for the delay; FF60 support was a huge effort.
---
** [bugs:#1964] NPE HtmlTextArea.removeFocus()**
**Status:** open
**Group:** Latest SVN
**Labels:** textarea NPE
**Created:** Fri Jun 01, 2018 08:35 AM UTC by Flake
**Last Updated:** Fri Jun 01, 2018 08:35 AM UTC
**Owner:** RBRi
Hi Ron,
I encountered a NPE that I didn't expect (haha). (2.32-SNAPSHOT)
Assume you have a textarea t. You type something in and then you need to blur it in order for some js to trigger.
~~~java
WebClient webClient = new WebClient(BrowserVersion.CHROME);
HtmlPage page = webClient.getPage("http://localhost:8080");
HtmlTextArea ta = HtmlPageTools.getHtmlElementById("ta", page);
ta.type("test");
ta.removeFocus();
webClient.close();
~~~
This is how I did it. I used the `removeFocus()` public API beause I didn't know there was `blur()` for textarea, too. However, by doing this you get a NPE because `valueAtFocus_` ain't seem to be set (because you didn't manually `focus()` it). I assumed it was focused after typing something in and it probably is but not via textarea's `focus()`. Actually, after taking a quick look im not sure if it's even focused.
The problematic line is this:
https://sourceforge.net/p/htmlunit/code/HEAD/tree/trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java#l515
The fix should be as easy as this:
~~~java
public void removeFocus() {
super.removeFocus();
if (valueAtFocus_ != null && !valueAtFocus_.equals(getText())) {
HtmlInput.executeOnChangeHandlerIfAppropriate(this);
}
valueAtFocus_ = null;
}
~~~
Best,
Ron2
---
Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/htmlunit/bugs/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop