Openbravo Issue Tracking System - Retail Modules
View Issue Details
0040474Retail ModulesSessionspublic2019-03-28 11:052019-05-22 10:40
aaroncalero 
ranjith_qualiantech_com 
highmajorrandom
closedfixed 
5
 
RR19Q3 
adrianromero
No
0040474: [Sessions] Completing multiple cashups simultaneously can cause NumberFormatExceptions
With the Sessions module installed, completing multiple cashups at the same time (which can happen in a production environment when all terminales close the cashups at the same time) can lead to NumberFormatException thrown in the server, leaving some of the cashups in the Errors While Importing POS Data window, with the following error*:

java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Long.parseLong(Long.java:601)
    at java.lang.Long.parseLong(Long.java:631)
    at java.text.DigitList.getLong(DigitList.java:195)
    at java.text.DecimalFormat.parse(DecimalFormat.java:2051)
    at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1869)
    at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1514)
    at java.text.DateFormat.parse(DateFormat.java:364)
    at org.openbravo.retail.sessions.CloseSessionHook.exec(CloseSessionHook.java:33)
    at org.openbravo.retail.posterminal.CashCloseProcessor.executeHooks(CashCloseProcessor.java:185)
    at org.openbravo.retail.posterminal.CashCloseProcessor.processCashClose(CashCloseProcessor.java:160)

* The NumberFormatException can vary (or the parsed date can be simply wrong):
java.lang.NumberFormatException: For input string: ""
java.lang.NumberFormatException: multiple points
java.lang.NumberFormatException: empty String
it is really hard to reproduce the issue manually/with an automated test, but the problem can be simulated using the attached patch.
The attached patch replicates the code found in the CloseSessionHook file[1], a static SimpleDateFormat and multiple accesses to its parse method.

1. Apply the patch, compile the application and start the server
2. Login in backend
3. Click on Help > About.
4. Verify in the server log that some exceptions are shown, and that the date has been parsed wrongly in some cases.


[1] https://code.openbravo.com/erp/pmods/org.openbravo.retail.sessions/file/tip/src/org/openbravo/retail/sessions/CloseSessionHook.java [^]
In the CloseSessionHook.java file the static modifier of the date formatter should be removed.
No tags attached.
related to defect 0040934 closed rqueralta [Sessions] Completing multiple open till simultaneously can cause NumberFormatExceptions 
diff SimulateNumberFormatException.diff (1,280) 2019-03-28 11:05
https://issues.openbravo.com/file_download.php?file_id=12800&type=bug
patch issue 40474 source sessions.patch (2,011) 2019-03-29 11:24
https://issues.openbravo.com/file_download.php?file_id=12810&type=bug
Issue History
2019-03-28 11:05aaroncaleroNew Issue
2019-03-28 11:05aaroncaleroAssigned To => Retail
2019-03-28 11:05aaroncaleroFile Added: SimulateNumberFormatException.diff
2019-03-28 11:05aaroncaleroResolution time => 1554933600
2019-03-28 11:05aaroncaleroTriggers an Emergency Pack => No
2019-03-28 12:20ranjith_qualiantech_comAssigned ToRetail => ranjith_qualiantech_com
2019-03-29 11:17ranjith_qualiantech_comStatusnew => scheduled
2019-03-29 11:24ranjith_qualiantech_comFile Added: issue 40474 source sessions.patch
2019-04-04 10:01ngarciaIssue Monitored: ngarcia
2019-04-05 08:43hgbotCheckin
2019-04-05 08:43hgbotNote Added: 0110985
2019-04-07 08:30ranjith_qualiantech_comStatusscheduled => resolved
2019-04-07 08:30ranjith_qualiantech_comResolutionopen => fixed
2019-04-15 12:31adrianromeroNote Added: 0111126
2019-04-15 12:31adrianromeroStatusresolved => new
2019-04-15 12:31adrianromeroResolutionfixed => open
2019-04-15 12:47ranjith_qualiantech_comStatusnew => scheduled
2019-04-15 12:49hgbotCheckin
2019-04-15 12:49hgbotNote Added: 0111130
2019-04-15 12:49hgbotStatusscheduled => resolved
2019-04-15 12:49hgbotResolutionopen => fixed
2019-04-15 12:49hgbotFixed in SCM revision => http://code.openbravo.com/erp/pmods/org.openbravo.retail.sessions/rev/7a3c2345e928587fcc716b25c130fe8405416910 [^]
2019-04-15 13:15adrianromeroReview Assigned To => adrianromero
2019-04-15 13:15adrianromeroNote Added: 0111133
2019-04-15 13:15adrianromeroStatusresolved => closed
2019-04-15 13:15adrianromeroFixed in Version => RR19Q3
2019-05-22 10:40ngarciaIssue cloned0040934
2019-05-22 10:40ngarciaRelationship addedrelated to 0040934

Notes
(0110985)
hgbot   
2019-04-05 08:43   
Repository: erp/pmods/org.openbravo.retail.sessions
Changeset: 166fa5e25c4d01ffd06727d63c95da85748f022c
Author: Ranjith S R <ranjith <at> qualiantech.com>
Date: Fri Apr 05 12:12:45 2019 +0530
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.sessions/rev/166fa5e25c4d01ffd06727d63c95da85748f022c [^]

Related to issue 40474 : Updated CloseSessionHook to parse Business Date

* If CloseSessionHook is called same time from multiple request, error occurs while parsing business date
  due to static identifier for DateFormat.

---
M src/org/openbravo/retail/sessions/CloseSessionHook.java
---
(0111126)
adrianromero   
2019-04-15 12:31   
The change moves the SimpleDateFormat instance to the method body instead of having an static instance. This is OK as SimpleDateFormat is not thread safe as indicated in the issue report.

But the change also captures the Exception when parsing and swallows it. The behaviour in case of exception must not be modified. The try - catch block around parse must be removed.
(0111130)
hgbot   
2019-04-15 12:49   
Repository: erp/pmods/org.openbravo.retail.sessions
Changeset: 7a3c2345e928587fcc716b25c130fe8405416910
Author: Ranjith S R <ranjith <at> qualiantech.com>
Date: Mon Apr 15 16:19:19 2019 +0530
URL: http://code.openbravo.com/erp/pmods/org.openbravo.retail.sessions/rev/7a3c2345e928587fcc716b25c130fe8405416910 [^]

Fixed issue 40474 : Updated CloseSessionHook to parse Business Date

* try-catch was removed. So it will follow the normal flow when exception occurred

---
M src/org/openbravo/retail/sessions/CloseSessionHook.java
---
(0111133)
adrianromero   
2019-04-15 13:15   
Verified