History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CASTOR-2044
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Werner Guttmann
Reporter: Shawn Crook
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
castor

The parseDuration(String) method does not respect the decimal place when converting the string representation of milliseconds into an integer/short.

Created: 13/Jul/07 09:45 AM   Updated: 14/Mar/08 06:41 AM
Component/s: XML
Affects Version/s: 1.1.2.1
Fix Version/s: 1.2

Time Tracking:
Original Estimate: 2 hours
Original Estimate - 2 hours
Remaining Estimate: 2 hours
Remaining Estimate - 2 hours
Time Spent: Not Specified
Remaining Estimate - 2 hours

File Attachments: 1. Java Source File Duration.java (25 kb)
2. Text File patch.c2044.20070911-002.txt (4 kb)
3. Text File patch.c2044.20070911.test.txt (15 kb)
4. Text File patch.c2044.20070911.txt (3 kb)

Environment: All

Patch Submitted: Yes


 Description  « Hide
ssue:
The parseDuration(String) method does not respect the decimal place when converting the string representation of milliseconds into an integer/short.
In cases where milliseconds are less than 100, the milliseconds are reported wrong.

Eg.
"0.001" milliseconds is wrongly reported as 100 milliseconds when getMilli() is called after parseDuration(String) "0.01" milliseconds is wrongly reported as 100 milliseconds when getMilli() is called after parseDuration(String) "1.001" milliseconds is wrongly reported as 1.1 seconds when getMilli() is called after parseDuration(String) "1.01" milliseconds is wrongly reported as 1.1 seconds when getMilli() is called after parseDuration(String)

Root Cause:
When the milliseconds are converted from a string to integer, the leading zero's after the decimal place are dropped.

Solution:
Prefix the string representation with a "1" prior to converting to integer and then drop the "1" prior to setting the milliseconds numeric value.

Recommendations:
This class should be refactored to perhaps use a float value to handle intermediate millisecond logic.
The setMilli() method does not need to accept a long as the max value should be 999. I think there is some confusion between get/setMilli and toLong() which is obvious by studing the code. An exception should be thrown if setMilli is supplied with anything > 999. Otherwise, additional logic needs to be added to ensure Y,D,H,M,S are updated accordingly also.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Werner Guttmann - 13/Jul/07 04:32 PM
Shawn, can you please supply us with a 'unified diff' against SVN trunk ? Let us know if you need any help with this ....

Werner Guttmann - 10/Sep/07 03:38 AM
Shawn ?

Werner Guttmann - 11/Sep/07 08:34 AM
Unified diff against SVN trunk.

Werner Guttmann - 11/Sep/07 08:51 AM
JUnit test case relative to codegen.

Werner Guttmann - 11/Sep/07 08:52 AM
Funny enough, the test case fails on the assertions regarding the milliseconds.

Werner Guttmann - 11/Sep/07 09:09 AM
Final patch for review.

Werner Guttmann - 11/Sep/07 09:10 AM
Had to patch DurationDescriptor as well to get things working ...