[jira] [Commented] (VELTOOLS-198) org.apache.velocity.tools.ConversionUtils#getNumberFormat(java.lang.String, java.util.Locale) is not thread safe for custom formats

2022-11-08 Thread Michael Osipov (Jira)


[ 
https://issues.apache.org/jira/browse/VELTOOLS-198?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17630583#comment-17630583
 ] 

Michael Osipov commented on VELTOOLS-198:
-

So basically we are talking about 
{{org.apache.velocity.tools.generic.NumberTool.getNumberFormat(String, 
Locale)]] and {{org.apache.velocity.tools.generic.NumberTool.format()}}? I 
agree that the NFs require external synchronization.

> org.apache.velocity.tools.ConversionUtils#getNumberFormat(java.lang.String, 
> java.util.Locale) is not thread safe for custom formats
> ---
>
> Key: VELTOOLS-198
> URL: https://issues.apache.org/jira/browse/VELTOOLS-198
> Project: Velocity Tools
>  Issue Type: Bug
>  Components: GenericTools
>Affects Versions: 3.1
>Reporter: Oscar Doral
>Priority: Major
>  Labels: pull-request-available
>
> org.apache.velocity.tools.ConversionUtils holds a cache for custom formats so 
> it can reuse formatters across different requests:
> {code:java}
> private static ConcurrentMap customFormatsCache = new 
> ConcurrentHashMap(); {code}
> Problem is formatters don't use to be thread safe so if same formatter is 
> used at the same time by two different threads we can get errors depending on 
> race conditions.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

-
To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org
For additional commands, e-mail: dev-h...@velocity.apache.org



[jira] [Commented] (VELTOOLS-198) org.apache.velocity.tools.ConversionUtils#getNumberFormat(java.lang.String, java.util.Locale) is not thread safe for custom formats

2022-11-08 Thread Oscar Doral (Jira)


[ 
https://issues.apache.org/jira/browse/VELTOOLS-198?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17630582#comment-17630582
 ] 

Oscar Doral commented on VELTOOLS-198:
--

I've created a pull request with a solution to move from ConcurrentMap to 
ThreadLocal [https://github.com/apache/velocity-tools/pull/12]

This way, formatters won't be shared between different threads.

> org.apache.velocity.tools.ConversionUtils#getNumberFormat(java.lang.String, 
> java.util.Locale) is not thread safe for custom formats
> ---
>
> Key: VELTOOLS-198
> URL: https://issues.apache.org/jira/browse/VELTOOLS-198
> Project: Velocity Tools
>  Issue Type: Bug
>  Components: GenericTools
>Affects Versions: 3.1
>Reporter: Oscar Doral
>Priority: Major
>  Labels: pull-request-available
>
> org.apache.velocity.tools.ConversionUtils holds a cache for custom formats so 
> it can reuse formatters across different requests:
> {code:java}
> private static ConcurrentMap customFormatsCache = new 
> ConcurrentHashMap(); {code}
> Problem is formatters don't use to be thread safe so if same formatter is 
> used at the same time by two different threads we can get errors depending on 
> race conditions.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

-
To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org
For additional commands, e-mail: dev-h...@velocity.apache.org