Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reassign property of Type Map fails with an EmptyStack exception #144

Open
Silviop22 opened this issue May 6, 2022 · 4 comments
Open

Reassign property of Type Map fails with an EmptyStack exception #144

Silviop22 opened this issue May 6, 2022 · 4 comments

Comments

@Silviop22
Copy link

Silviop22 commented May 6, 2022

Hi guys, I noticed you had an old PR regarding this issue but I am still facing this exact issue on 4.2.6.

Below is an amateur way to replicate the issue:
@GetMapping("/test-mapping") public String testMapper() { FromObject from = new FromObject(); from.setFromId("id"); LinkedHashMap<String, String> hashMapValue = new LinkedHashMap<>(); hashMapValue.put("key1", "value1"); hashMapValue.put("key2", "value2"); from.setFromMap(hashMapValue); ToObject toObject = objectMapper.map(from); return "OK"; }

And here is the stack trace:
java.util.EmptyStackException: null at java.base/java.util.Stack.peek(Stack.java:101) at com.remondis.remap.GenericParameterContext.get(GenericParameterContext.java:88) at com.remondis.remap.GenericParameterContext.findNextGenericTypeFromMethod(GenericParameterContext.java:119) at com.remondis.remap.GenericParameterContext.goInto(GenericParameterContext.java:105) at com.remondis.remap.ReassignTransformation.convertMap(ReassignTransformation.java:108) at com.remondis.remap.ReassignTransformation._convert(ReassignTransformation.java:75) at com.remondis.remap.ReassignTransformation.performValueTransformation(ReassignTransformation.java:61) at com.remondis.remap.ReassignTransformation.performTransformation(ReassignTransformation.java:48) at com.remondis.remap.Transformation.performTransformation(Transformation.java:86) at com.remondis.remap.ReassignTransformation.performTransformation(ReassignTransformation.java:23) at com.remondis.remap.MappingConfiguration.map(MappingConfiguration.java:727) at com.remondis.remap.MappingConfiguration.map(MappingConfiguration.java:707) at com.remondis.remap.Mapper.map(Mapper.java:40)

I decompiled the jar and noticed that the issue only happens when the property of the source is of type Map.
Now I do have a few workarounds for this on my side:

  • Downgrade to version 4.1.0
  • Store those Map properties as custom POJOs (my current implementation includes Map types only because of jackson mapper so the Map type is not necessary there)

However I just wanted to let you guys know on the issue since it was strange for me at first. I would not expect the mapper to just break all of the sudden.

@schuettec
Copy link
Contributor

Thx. I'm on it.

@schuettec
Copy link
Contributor

Can you please send the mapping configuration or a reproducing, minimal example?
I'm able to reproduce an exception, but it's not the one you mentioned.

schuettec added a commit that referenced this issue May 11, 2022
Findings:
Currently the mapper analyzes the type of properties. If the source
value of a property is an instance of a Map, the map conversion is
triggered.
The map conversion creates a map instance using Collectors.toMap
function. The map instance might not be assignment compatible with the
target value of the bean.

This is some kind of hidden convention: The problem does not occur as
long as the bean properties use super types like Map, List, Set etc.
@schuettec
Copy link
Contributor

I created a PR to reproduce the problem. See #145, is this what you did in your mapping config?

@Silviop22
Copy link
Author

Sorry @schuettec, been mad busy. Yeap that is pretty much it. So using a super type seems like a workaround, but IDK if you guys see it as a long term fix. There could be numerous cases where the bean properties could be non-super types created by another library such as jackson or something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants