You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by "sharanggupta (via GitHub)" <gi...@apache.org> on 2026/10/22 00:11:32 UTC

[I] MapProperty(String, Map) stores every value as StringProperty [jmeter]

sharanggupta opened a new issue, #6830:
URL: https://github.com/apache/jmeter/issues/6830

   ### Expected behavior
   
   `new MapProperty("foo", map)` keeps the type of each value. A `Map<String, Integer>` becomes `IntegerProperty` elements, as `MapPropertyTest.testGetPropertyTypeOfStringElements` expects:
   
   ```java
   Map<String, Integer> numberMap = new HashMap<>();
   numberMap.put("One", 1);
   MapProperty props = new MapProperty("foo", numberMap);
   assertEquals(IntegerProperty.class, props.getPropertyType());
   ```
   
   ### Actual behavior
   
   Every non-property value is stored as a `StringProperty`. The test above fails with `expected: <IntegerProperty> but was: <StringProperty>`.
   
   It has never been noticed because the test method has no `@Test` annotation. It was added that way in d3a0d3290c (2018), so it has never run.
   
   The cause:
   
   1. The [`MapProperty(String, Map)`](https://github.com/apache/jmeter/blob/master/src/core/src/main/java/org/apache/jmeter/testelement/property/MapProperty.java#L33-L38) constructor calls `normalizeMap(value)` before its `value` field is set.
   2. `normalizeMap` converts each value with [`convertObject`](https://github.com/apache/jmeter/blob/master/src/core/src/main/java/org/apache/jmeter/testelement/property/AbstractProperty.java#L396-L404). For a plain `Integer`, `makeProperty` returns null, so `convertObject` calls the instance `getBlankProperty()`.
   3. That calls `MapProperty.getPropertyType()`, which reads `value.isEmpty()` while `value` is still null. The `NullPointerException` is caught in [`getBlankProperty()`](https://github.com/apache/jmeter/blob/master/src/core/src/main/java/org/apache/jmeter/testelement/property/AbstractProperty.java#L262-L272), which falls back to `new StringProperty()`.
   
   Even with `value` initialised, an empty map gives `NullProperty`, which `getBlankProperty()` also turns into a `StringProperty`. So getting `IntegerProperty` needs a per-value type, like the static `getBlankProperty(Object item)` that `createProperty` uses.
   
   That choice would also affect `CollectionProperty` through `normalizeList`, so I'd like to check the intended behaviour first. If per-value types are what you want, I can send a pull request. It would use the static variant in `convertObject` and add `@Test` to the existing test.
   
   (Side note: the same constructor logs the whole map at INFO level twice, `log.info("map = {}", value)` and `log.info("normalized map = {}", this.value)`, which looks like leftover debugging.)
   
   ### Steps to reproduce the problem
   
   Add `@Test` to `MapPropertyTest.testGetPropertyTypeOfStringElements` in `src/core` and run `./gradlew :src:core:test --tests org.apache.jmeter.testelement.property.MapPropertyTest`.
   
   ### JMeter Version
   
   master (commit d3a0d3290c added the test in 2018)
   
   ### Java Version
   
   17
   
   ### OS Version
   
   macOS
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jmeter.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org