Bug 65864 - NullPointerException when recording jmeter test plan
Summary: NullPointerException when recording jmeter test plan
Status: RESOLVED FIXED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 5.4.3
Hardware: PC All
: P2 normal (vote)
Target Milestone: JMETER_5.5
Assignee: JMeter issues mailing list
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2022-02-02 08:45 UTC by f0xb4t
Modified: 2022-02-06 11:57 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description f0xb4t 2022-02-02 08:45:40 UTC
I'm getting below exception in jMeter 5.4.3 when recording Test Plan:

2022-02-01 20:59:35,150 ERROR o.a.j.p.h.p.Proxy: [64794]  Exception when processing sample java.lang.NullPointerException: null
    at  org.jsoup.parser.HtmlTreeBuilderState$9.process(HtmlTreeBuilderState.java:934) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.HtmlTreeBuilder.process(HtmlTreeBuilder.java:141) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.HtmlTreeBuilderState$14.anythingElse(HtmlTreeBuilderState.java:1227) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.HtmlTreeBuilderState$14.process(HtmlTreeBuilderState.java:1191) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.HtmlTreeBuilder.process(HtmlTreeBuilder.java:136) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.HtmlTreeBuilderState$10.process(HtmlTreeBuilderState.java:1019) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.HtmlTreeBuilder.process(HtmlTreeBuilder.java:136) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.TreeBuilder.runParser(TreeBuilder.java:66) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.TreeBuilder.parse(TreeBuilder.java:47) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.parser.Parser.parse(Parser.java:107) ~[jsoup-1.13.1.jar:?]
    at org.jsoup.Jsoup.parse(Jsoup.java:58) ~[jsoup-1.13.1.jar:?]
    at org.apache.jmeter.protocol.http.proxy.FormCharSetFinder.addFormActionsAndCharSet(FormCharSetFinder.java:55) ~[ApacheJMeter_http.jar:5.4.3]
    at org.apache.jmeter.protocol.http.proxy.Proxy.addFormEncodings(Proxy.java:629) ~[ApacheJMeter_http.jar:5.4.3]
    at org.apache.jmeter.protocol.http.proxy.Proxy.run(Proxy.java:250) [ApacheJMeter_http.jar:5.4.3]
2022-02-01 20:59:35,153 WARN o.a.j.p.h.p.Proxy: [64794]  Exception while writing error
java.net.SocketException: Software caused connection abort: socket write error
    at java.net.SocketOutputStream.socketWrite0(Native Method) ~[?:1.8.0_131]
    at java.net.SocketOutputStream.socketWrite(Unknown Source) ~[?:1.8.0_131]
    at java.net.SocketOutputStream.write(Unknown Source) ~[?:1.8.0_131]
    at java.io.DataOutputStream.writeBytes(Unknown Source) ~[?:1.8.0_131]
    at org.apache.jmeter.protocol.http.proxy.Proxy.writeErrorToClient(Proxy.java:580) [ApacheJMeter_http.jar:5.4.3]
    at org.apache.jmeter.protocol.http.proxy.Proxy.run(Proxy.java:269) [ApacheJMeter_http.jar:5.4.3]
2022-02-01 20:59:40,717 INFO o.a.j.p.h.p.Daemon: HTTP(S) Test Script Recorder stopped

When it happens the browser stops loading the page and its console shows:

 net::ERR_ABORTED 500 (Internal server error)

The browsers are Chrome 97.0.4692.99 and Firefox 91.5.1esr. During regular use, without jMeter Proxy recorder, the web page behaves normally. Can't see anything bad in the web server logs.
Comment 1 Felix Schumacher 2022-02-02 10:59:01 UTC
Thanks for the stacktrace and the issue report.

Could you try a current nightly (might be fixed in a newer version of jsoup, which is included in the nightly build)?

Could you enable debug logging for the class org.apache.jmeter.protocol.http.proxy.FormCharSetFinder (add a Logger with this class (name) to bin/log4j2.xml). JMeter should then log a debug statement with "Parsing html of: X" right before the NPE. Can you share the content of the displayed html page (The X)?
Comment 2 Felix Schumacher 2022-02-02 15:54:32 UTC
I committed a try-catch block to re-declare all runtime exceptions thrown by JSoup.parse to be a HTMLParseException. That should get you going again, but still, could you send us the HTML fragment, that causes the NPE?

commit a1b170de57f7f32a333aec2db9bb4d1823f44258
AuthorDate: Wed Feb 2 16:49:57 2022 +0100

    Catch NullPointerException from JSoup when recording a test plan
    
    As reported in the bug issue, JSoup throws a NPE on some input.
    When we know more about that input, we might be able to do
    better, for now, let us wrap the exception into the declared
    HTMLParseException and hope, that we can continue.
    
    Bugzilla Id: 65864
---
 .../org/apache/jmeter/protocol/http/proxy/FormCharSetFinder.java    | 6 +++++-
 xdocs/changes.xml                                                   | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
Comment 3 Felix Schumacher 2022-02-02 15:58:38 UTC
commit 3a74a92b298b0d32cfc96a689c8fc95125201dde
AuthorDate: Wed Feb 2 16:56:54 2022 +0100

    Catch NullPointerException from JSoup when recording a test plan
    
    Fix stupid bug, where I placed the declaration of the method
    variable inside the try-catch block.
    
    Bugzilla Id: 65864
---
 .../java/org/apache/jmeter/protocol/http/proxy/FormCharSetFinder.java  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Comment 4 f0xb4t 2022-02-03 18:07:24 UTC
No issues when execute failing scenario with use of apache-jmeter-5.5-SNAPSHOT 3a74a92 taken 22/02/03.
Comment 5 Felix Schumacher 2022-02-06 11:57:46 UTC
I got more info on the circumstances, when this error happens. It fails on parsing a Javascript resource (with a content-type of application/javascript;charset=UTF-8).

There are a few things, that I don't understand here. JMeter version 5.4.3 has a guard clause before parsing resources and it should not try to parse javascript resources, when the content-type starts with application/javascript. Another strange thing is, that when I try to parse the javascript resource within a unit test (I got the log file with the complete javascript resource privately), no exception is thrown by the jsoup parser.

But given, that OP said, that the fix in trunk helps, I will close this bug.
Comment 6 The ASF infrastructure team 2022-09-24 20:38:23 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/5626