Skip to content

Commit

Permalink
Fixing thread safety of string matching
Browse files Browse the repository at this point in the history
Based on 361656d
  • Loading branch information
buma committed Jan 27, 2015
1 parent d6cd4d7 commit a94bfc3
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -28,8 +28,7 @@ the License, or (at your option) any later version.
* @author mabu * @author mabu
*/ */
public class LocalizedString implements I18NString, Serializable { public class LocalizedString implements I18NString, Serializable {
private static final Pattern pattern = Pattern.compile("\\{(.*?)\\}"); private static final Pattern patternMatcher = Pattern.compile("\\{(.*?)\\}");
private static final Matcher matcher = pattern.matcher("");


/** /**
* Map which key has which tagName. Used only when building graph. * Map which key has which tagName. Used only when building graph.
Expand Down Expand Up @@ -100,7 +99,8 @@ private String getTagNames() {
return key_params.get(key); return key_params.get(key);
} }
String english_trans = ResourceBundleSingleton.INSTANCE.localize(this.key, Locale.ENGLISH); String english_trans = ResourceBundleSingleton.INSTANCE.localize(this.key, Locale.ENGLISH);
matcher.reset(english_trans);
Matcher matcher = patternMatcher.matcher(english_trans);
int lastEnd = 0; int lastEnd = 0;
while (matcher.find()) { while (matcher.find()) {


Expand All @@ -127,7 +127,7 @@ public String toString(Locale locale) {
//in string formatting with values from way tags values //in string formatting with values from way tags values
String translation = ResourceBundleSingleton.INSTANCE.localize(this.key, locale); String translation = ResourceBundleSingleton.INSTANCE.localize(this.key, locale);
if (this.params != null) { if (this.params != null) {
translation = pattern.matcher(translation).replaceFirst("%s"); translation = patternMatcher.matcher(translation).replaceFirst("%s");
return String.format(translation, (Object[]) params); return String.format(translation, (Object[]) params);
} else { } else {
return translation; return translation;
Expand Down

0 comments on commit a94bfc3

Please sign in to comment.