Openbravo Issue Tracking System - Retail Modules
View Issue Details
0045359Retail ModulesWeb POSpublic2020-11-02 18:222020-11-19 08:06
aaroncalero 
prakashmurugesan88 
highmajorrandom
closedfixed 
5
 
RR21Q1 
No
0045359: Static Dateformatter in JSONPropertyToEntity.java can cause random errors if accessed simultaneously
Java DateFormatters are not thread-safe, so when a formatter is defined as static and accessed simultaneously, it can behave incorrectly.
There is a static DateFormatter in JSONPropertyToEntity, which is in charge of parsing json objects to set properties to entities.
If this class is invoked from two different threads, and two date properties are processed at the same time, one of them could fail.
It is not possible to reproduce this manually, but we have seen the following error in a client environment:
2020-11-01 10:17:58,164 [http-11] ERROR org.openbravo.retail.posterminal.CustomerAddrLoader - Exception while updating BPartner Address
java.lang.NumberFormatException: For input string: "2020-10-03T14:20:42+02:00"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_232]
    at java.lang.Long.parseLong(Long.java:589) ~[?:1.8.0_232]
    at java.lang.Long.valueOf(Long.java:803) ~[?:1.8.0_232]
    at org.openbravo.mobile.core.process.JSONPropertyToEntity.fillBobFromJSON(JSONPropertyToEntity.java:113) ~[classes/:?]
    at org.openbravo.mobile.core.process.JSONPropertyToEntity.fillBobFromJSON(JSONPropertyToEntity.java:37) ~[classes/:?]
    at org.openbravo.retail.posterminal.CustomerAddrLoader.editBPartnerAddr(CustomerAddrLoader.java:191) [classes/:?]
The static modifier here[1] should be removed, and a new dateFormatter instance should be created each time it is needed.

[1] https://gitlab.com/openbravo/product/pmods/org.openbravo.mobile.core/-/blob/master/src/org/openbravo/mobile/core/process/JSONPropertyToEntity.java#L33 [^]

Examples of other issues where the same fix was applied: 0040474, 0040934
No tags attached.
Issue History
2020-11-02 18:22aaroncaleroNew Issue
2020-11-02 18:22aaroncaleroAssigned To => Retail
2020-11-02 18:22aaroncaleroResolution time => 1606086000
2020-11-02 18:22aaroncaleroTriggers an Emergency Pack => No
2020-11-19 06:10prakashmurugesan88Assigned ToRetail => prakashmurugesan88
2020-11-19 06:10prakashmurugesan88Statusnew => scheduled
2020-11-19 06:53hgbotNote Added: 0124499
2020-11-19 08:06hgbotResolutionopen => fixed
2020-11-19 08:06hgbotStatusscheduled => closed
2020-11-19 08:06hgbotNote Added: 0124500
2020-11-19 08:06hgbotFixed in Version => RR21Q1
2020-11-19 08:06hgbotNote Added: 0124501

Notes
(0124499)
hgbot   
2020-11-19 06:53   
Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.mobile.core/-/merge_requests/104 [^]
(0124500)
hgbot   
2020-11-19 08:06   
Merge request merged: https://gitlab.com/openbravo/product/pmods/org.openbravo.mobile.core/-/merge_requests/104 [^]
(0124501)
hgbot   
2020-11-19 08:06   
Directly closing issue as related merge request is already approved.

Repository: https://gitlab.com/openbravo/product/pmods/org.openbravo.mobile.core [^]
Changeset: f63be5ebbbe2b15057fe48ecf86818cc4c8c34dc
Author: Prakash M <prakash@qualiantech.com>
Date: 2020-11-19T11:15:53+05:30
URL: https://gitlab.com/openbravo/product/pmods/org.openbravo.mobile.core/-/commit/f63be5ebbbe2b15057fe48ecf86818cc4c8c34dc [^]

Fixed BUG-45359: Fixes NumberFormatExceptions when JSONPropertyToEntity is called simultaneously
* If JSONPropertyToEntity is called same time from multiple request, error occurs while parsing date
due to static identifier for DateFormat.

---
M src/org/openbravo/mobile/core/process/JSONPropertyToEntity.java
---