grails - Is Map attribute in DefaultLinkGenerator link() method thread safe? -
grails - Is Map attribute in DefaultLinkGenerator link() method thread safe? -
we built grails (2.3.7) application overriding link(map attr, string encoding = 'utf-8') in defaultlinkgenerator class. reason doing have same url throughout our application business requirement customer. in overriding link() method, modifying map new request parameters.
now in production seeing next exception occurs sporadically , haven't been able reproduce locally.
2014-09-29 01:04:06,257 stacktrace error total stack trace: java.lang.arrayindexoutofboundsexception: 3 @ org.codehaus.groovy.grails.web.mapping.urlcreatorcache$reversemappingkey.<init>(urlcreatorcache.java:196) @ org.codehaus.groovy.grails.web.mapping.urlcreatorcache.createkey(urlcreatorcache.java:62) @ org.codehaus.groovy.grails.web.mapping.defaulturlmappingsholder.getreversemappingnodefault(defaulturlmappingsholder.java:265) @ org.codehaus.groovy.grails.web.mapping.defaulturlmappingsholder.getreversemappingnodefault(defaulturlmappingsholder.java:257) @ org.codehaus.groovy.grails.web.mapping.defaultlinkgenerator.link(defaultlinkgenerator.groovy:213) @ gov.texas.multitenant.core.mapping.multitenantlinkgenerator.super$2$link(multitenantlinkgenerator.groovy)
the code in 'urlcreatorcache$reversemappingkey' throws above arrayindexoutofexception can happen when map attribute (params) gets mutated during loop. excerpt of code below.
paramkeys = new string[params.size()]; paramvalues = new string[params.size()]; int = 0; (map.entry entry : params.entryset()) { **paramkeys[i] = string.valueof(entry.getkey());** //throws exception here string value = null; if (entry.getvalue() instanceof charsequence) { value = string.valueof(entry.getvalue()); } ... paramvalues[i] = value; i++; }
now question is, map attribute thread safe? can mutated between threads since modifying it?
any feedback great appreciated. in advance.
you wouldn't know within method - implementing map
interface allowable. that's not of import - you're causing problem (by beingness 1 of 2 concurrent editors of apparently non-threadsafe instance) , can prepare it.
instead of modifying map, create new 1 (any map
implementation since code , code in method can access it) , modify that, , pass in link generation. throw away , utilize real map farther calculations. like
def attrs = ... // 'real' map def re-create = [:] + attrs copy.foo = 42 copy.bar = 'a high 1 indeed' string link = linkgenerator.link(copy) // ... def foo = attrs.foo // not available, set in copy, no longer using ...
grails
Comments
Post a Comment