Bug 62281 - Cannot Load MapProperty - java.lang.NullPointerException
Summary: Cannot Load MapProperty - java.lang.NullPointerException
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 4.0
Hardware: PC All
: P2 major (vote)
Target Milestone: JMETER_5.0
Assignee: JMeter issues mailing list
URL:
Keywords: FixedInTrunk, PatchAvailable
Depends on:
Blocks:
 
Reported: 2018-04-10 20:53 UTC by belugabehr
Modified: 2018-09-05 15:35 UTC (History)
1 user (show)



Attachments
JMX files which causes NPE (2.30 KB, application/xml)
2018-04-12 14:57 UTC, belugabehr
Details
JMeter Log File - INFO level (25.77 KB, text/plain)
2018-04-12 15:01 UTC, belugabehr
Details
Proposed patch (680 bytes, patch)
2018-04-17 19:54 UTC, belugabehr
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description belugabehr 2018-04-10 20:53:40 UTC
I'm guessing it's because the default constructor for MapProperty does not instantiate an internal map and therefore, when the serializer creates an instance of MapProperty and tries to add a property, it fails.

The CollectionProperty class creates an internal ArrayList when the default constructor is called, for example.


Caused by: java.lang.NullPointerException
	at org.apache.jmeter.testelement.property.MapProperty.addProperty(MapProperty.java:137) ~[ApacheJMeter_core.jar:4.0 r1823414]
	at org.apache.jmeter.testelement.property.MapProperty.addProperty(MapProperty.java:75) ~[ApacheJMeter_core.jar:4.0 r1823414]
	at org.apache.jmeter.save.converters.MultiPropertyConverter.unmarshal(MultiPropertyConverter.java:71) ~[ApacheJMeter_core.jar:4.0 r1823414]
	at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) ~[xstream-1.4.10.jar:1.4.10]
	at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:70) ~[xstream-1.4.10.jar:1.4.10]
	at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) ~[xstream-1.4.10.jar:1.4.10]
	at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) ~[xstream-1.4.10.jar:1.4.10]
	at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:73) ~[xstream-1.4.10.jar:1.4.10]
	at org.apache.jmeter.save.converters.MultiPropertyConverter.unmarshal(MultiPropertyConverter.java:69) ~[ApacheJMeter_core.jar:4.0 r1823414]
	at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) ~[xstream-1.4.10.jar:1.4.10]
	at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:70) ~[xstream-1.4.10.jar:1.4.10]
	at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) ~[xstream-1.4.10.jar:1.4.10]
	at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) ~[xstream-1.4.10.jar:1.4.10]
Comment 1 Philippe Mouawad 2018-04-10 20:59:22 UTC
Hello,
Could you provide a reproducer for this issue ?

How does it happen ?
A JMX plan or junit test is very welcome.

Regards
Comment 2 Philippe Mouawad 2018-04-10 21:08:03 UTC
(In reply to Philippe Mouawad from comment #1)
> Hello,
> Could you provide a reproducer for this issue ?
> 
> How does it happen ?
> A JMX plan or junit test is very welcome.
> 
> Regards

And jmeter.log
Comment 3 belugabehr 2018-04-10 21:29:22 UTC
Thank you for the quick response.

I am working on a custom component that spits out MapProperty objects.

https://github.com/apache/jmeter/blob/f2e65bc2f264d4bd7da83279dbdcf236da6edfe3/src/core/org/apache/jmeter/save/converters/MultiPropertyConverter.java#L64-L76


#####
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
        MultiProperty prop = (MultiProperty) createCollection(context.getRequiredType());
        prop.setName(ConversionHelp.decode(reader.getAttribute(ConversionHelp.ATT_NAME)));
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            JMeterProperty subProp = (JMeterProperty) readItem(reader, context, prop);
            if (subProp != null) { // could be null if it has been deleted via NameUpdater
                prop.addProperty(subProp);
            }
            reader.moveUp();
        }
        return prop;
    }

#####

The MultiProperty is created, almost certainly with the default constructor, which does not create a default internal data structure for MapProperty.  It then calls "addProperty" which triggers the NPE.

The unit test would be to simply create the MapProperty with the default constructor, then call "addProperty" method on it.
Comment 4 belugabehr 2018-04-12 14:57:00 UTC
Created attachment 35861 [details]
JMX files which causes NPE
Comment 5 belugabehr 2018-04-12 15:01:10 UTC
Created attachment 35862 [details]
JMeter Log File - INFO level
Comment 6 belugabehr 2018-04-12 15:01:23 UTC
Attached requested files.
Comment 7 UbikLoadPack support 2018-04-13 13:19:58 UTC
Hello,
How did you create this JMX file ?
Could you provide the program ?

Thanks
Comment 8 belugabehr 2018-04-13 16:45:56 UTC
I created it with JUnit and then hand modified it to pull out the irrelevant parts thereby simplify the error space.
Comment 9 belugabehr 2018-04-13 16:47:24 UTC
I'm guessing it's failing the default constructor for MapProperty does not instantiate an internal map and therefore, when the serializer creates an instance of MapProperty and tries to add a property, it fails.

The CollectionProperty class creates an internal ArrayList when the default constructor is called.  Please do the same for MapProperty.
Comment 10 belugabehr 2018-04-17 19:54:35 UTC
Created attachment 35879 [details]
Proposed patch
Comment 11 Felix Schumacher 2018-06-03 16:26:11 UTC
Thanks for your contribution.

I can't get your jmx file to work, but I think that is because the jmx file is not correct.

It would be nice, if you could check, whether the fix works for you.

Date: Sun Jun  3 13:44:15 2018
New Revision: 1832768

URL: http://svn.apache.org/viewvc?rev=1832768&view=rev
Log:
Prevent NPE in MapProperty.

Initialize the backing Map when no Map was passed into constructor.
Patch by belugabehr (dam6923 at gmail.com)

Bugzilla Id: 62281

Added:
    jmeter/trunk/test/src/org/apache/jmeter/testelement/property/MapPropertyTest.java   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/testelement/property/MapProperty.java
    jmeter/trunk/xdocs/changes.xml