[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/ae9ffa4d55d18951281aa0bc01a6d32292fc3d8e.bugs@htmlunit.p.sourceforge.net>
- **status**: open --> closed



---

** [bugs:#1964] NPE HtmlTextArea.removeFocus()**

**Status:** closed
**Group:** Latest SVN
**Labels:** textarea NPE 
**Created:** Fri Jun 01, 2018 08:35 AM UTC by Flake
**Last Updated:** Fri Jun 29, 2018 02:19 PM 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.