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

Need a mechanism to avoid calling entrySet() on java.util.Map properties [SPR-3407] #8090

Closed
spring-issuemaster opened this Issue Apr 24, 2007 · 1 comment

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Apr 24, 2007

Scott Bartram opened SPR-3407 and commented

TypeConverterDelegate.convertIfNecessary() method always calls convertToTypedMap() if the property implements the java.util.Map interface. The convertToTypedMap() method always calls java.util.Map.entrySet() on the property. When that property is something like a distributed cache containing a very large number of objects, iteration over the map must be avoided. There should be some way to prevent or override the call to convertToTypedMap().


Affects: 2.0.4

Referenced from: commits spring-projects/spring-boot@2126c77

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Apr 30, 2007

Juergen Hoeller commented

Indeed, this code assumes that Maps are always statically specified value Maps of reasonably small size.

I've optimized this analogously to our array conversion optimizations in 2.0.1: We check in advance whether there is any point in trying to convert elements, checking for generic key/value types as well as for custom editors for this particular collection. This means that we don't even try to create a typed collection, avoiding to iterate over the collection's original elements just to find out that no element had to be converted in the first place.

So in your scenario, as long as the target property is not declared as typed Map but rather just as plain Map, no conversion will be attempted, hence no iteration of the original entries will happen. Note, however, that a Map<String, Object> declaration (or the like) would still trigger a check of all keys... Consider declaring your receiving property/argument as plain Map in this case, internally accessing it as typed Map through a cast.

This refinement will be available in the next 2.0.5 snapshot (http://www.springframework.org/snapshots). Please give it a try and let us know whether it works for you!

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment