Bug 61050 - Crash in JMeterUtils due to null ResourceBundle in method getResStringDefault while trying to use DurationAssertion
Summary: Crash in JMeterUtils due to null ResourceBundle in method getResStringDefault...
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 3.2
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-27 07:18 UTC by chuha.billi
Modified: 2017-05-20 14:26 UTC (History)
1 user (show)



Attachments
Get a ResourceBundle, even if it hasn't been initialized, yet (2.56 KB, patch)
2017-05-01 15:34 UTC, Felix Schumacher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description chuha.billi 2017-04-27 07:18:58 UTC
while trying to use the DurationAssertion as follows, I am getting a crash, looking into code and debugging it looks like the ResourceBundle object in method  private static String getResStringDefault(String key, String defaultValue, Locale forcedLocale) 

is null and hence crashing with null pointer exception. 

following is the code that I am using

		// Create a JMeter 
		ThreadGroup threadGroup = jmeterTreeManager.createThreadGroup("TestCase1_Rest", 1, 1);
		HashTree threadGroupHashTree = jmeterTreeManager.addThreadGroupToRootTree(testPlan, threadGroup);

		// Create HTTP Sampler 
		HTTPSamplerProxy httpSampler = new HTTPSamplerProxy();
		httpSampler.setDomain(testConfigs.getDomain());
		httpSampler.setPort(Integer.parseInt(HTTPConstants.DEFAULT_HTTPS_PORT_STRING));
		httpSampler.setProtocol(HTTPConstants.PROTOCOL_HTTPS); 
		httpSampler.setPath("api/");
		httpSampler.setMethod(HTTPConstants.POST);
		httpSampler.addArgument("apikey", testConfigs.getApiKey());
		httpSampler.setName("FixureRequest");
		httpSampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
		httpSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());

		// Get result from sampler
		HTTPSampleResult samplerResult = (HTTPSampleResult) httpSampler.sample();  
		
		// Create Response Assertion
		ResponseAssertion responseAssertion = new ResponseAssertion();
		responseAssertion.setName("ResponseAssertionForRest");
		//responseAssertion.setTestFieldRequestHeaders();
		responseAssertion.setTestFieldResponseData();
		
		/**note : Contains, Matches: Perl5-style regular expressions
		  *       Equals, Substring: plain text, case-sensitive
		*/
		
		responseAssertion.setToSubstringType();
		responseAssertion.addTestString("\"started\":false");
		responseAssertion.setEnabled(true);
		

		
		// Create Duration Assertion
		DurationAssertion durationAssertion = new DurationAssertion();
		durationAssertion.setName("DurationAssertionForRest");
		durationAssertion.setScopeAll();
		durationAssertion.setAllowedDuration(1);
		durationAssertion.setEnabled(true);

		// Get assertion result from received response
		AssertionResult assertionResult = responseAssertion.getResult(samplerResult);
		AssertionResult durationAsserRes = durationAssertion.getResult(samplerResult);

following is the crash stack

java.lang.NullPointerException
	at org.apache.jmeter.util.JMeterUtils.getResStringDefault(JMeterUtils.java:515)
	at org.apache.jmeter.util.JMeterUtils.getResStringDefault(JMeterUtils.java:496)
	at org.apache.jmeter.util.JMeterUtils.getResString(JMeterUtils.java:451)
	at org.apache.jmeter.assertions.DurationAssertion.getResult(DurationAssertion.java:57)
	at com.incontact.test.testsuite.jmeter.TestSuite_RestApiAccess.RestApi_TestCase1(TestSuite_RestApiAccess.java:100)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
	at org.testng.TestRunner.privateRun(TestRunner.java:744)
	at org.testng.TestRunner.run(TestRunner.java:602)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
	at org.testng.SuiteRunner.run(SuiteRunner.java:289)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
	at org.testng.TestNG.runSuites(TestNG.java:1144)
	at org.testng.TestNG.run(TestNG.java:1115)
	at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Comment 1 Philippe Mouawad 2017-04-27 18:07:53 UTC
Please ask such questions on user mailing lists.

Bugzilla is not a support forum.
Regards
Comment 2 chuha.billi 2017-04-28 05:57:21 UTC
Hi Phillippe,

I understand the sentiment, but while digging up in the JMeter code I found out that in in Class JMeterUtils and method getResStringDefault the bundle is assigned the reference of resources object as ResourceBundle bundle = resources;, now the resources object is initialized only if the locale is set, if not set then the bundle is null and that then before accessing the bundle the check of it being not null is not checked. which causes the crash.

now if this is designed like this then setting locale is mandatory but if not then I think won't it be a good option to do a null check before using the object and if found null then setting locale using system default values.?? This was the query in my mind with which I raised the bug.
Comment 3 Philippe Mouawad 2017-04-28 06:16:10 UTC
Thanks for feedback and analysis.
Reopening for fix.
Comment 4 Felix Schumacher 2017-05-01 15:34:41 UTC
Created attachment 34966 [details]
Get a ResourceBundle, even if it hasn't been initialized, yet

Get a ResourceBundle before we use it. If it has been initialized and no forcedLocal is given, use that. If it is forced, try to use the forced one, or use a fall back.
Comment 5 Philippe Mouawad 2017-05-01 15:40:45 UTC
Comment on attachment 34966 [details]
Get a ResourceBundle, even if it hasn't been initialized, yet

looks good to me.
Thanks
Comment 6 Felix Schumacher 2017-05-20 14:26:15 UTC
Thanks for the report. Feel free to reopen this, if it is not fixed for you.

This will be included in JMeter version 3.3.

Date: Sat May 20 14:21:26 2017
New Revision: 1795657

URL: http://svn.apache.org/viewvc?rev=1795657&view=rev
Log:
Handle uninitialized RessourceBundle more gracefully.

Bugzilla Id: 61050

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java
    jmeter/trunk/test/src/org/apache/jmeter/util/TestJMeterUtils.java

Date: Sat May 20 14:24:29 2017
New Revision: 1795658

URL: http://svn.apache.org/viewvc?rev=1795658&view=rev
Log:
Add changelog entry for: Handle uninitialized RessourceBundle more gracefully.

Bugzilla Id: 61050

Modified:
    jmeter/trunk/xdocs/changes.xml