Open OungKennedy opened 4 years ago
Accepted. This bug was not caught by our team, because we were testing the undo and redo function on a MacOS. After this bug was highlighted, we tried to determine the cause of the problem.
| Operating System | Java Version | Bug Status|
|----|----|----|
| Windows 10 | Java 11.0.4 | Undo and Redo lead to loss of data and concatenation of distinct statelist elements. |
| MacOS El Capitan | Java 11.0.4 | No bug. |
| MacOS Catalina | Java 11.0.4 | No bug. |
| Ubuntu 18.04 | Java 11.0.4 | No bug. |
The bug occurs because we used System.getProperty("line.separator") to split our line of our state data string. However, when this state data is created, it is created by explicitly appending a "\n". However, when reading the string, using System.getProperty("line.separator") causes an error in Windows, because in windows line separators are "\r\n" instead of simply "\n". Here is a link to explain this difference in how DOS handles line separators compared to UNIX bases systems such as the MacOS
Link : UNIX vs DOS Line Seperator.
I also managed to fix this issue by changing all instances of System.getProperty("line.separator") to "\n" as shown in the screenshot below.
See lines 29, 34, 55. This fixes the issue because now, the state data string is read exactly the same way as it was saved, regardless of operating system.
Redo
command which is dependent on the Undo
commandI have set all the related undo and redo issues which broke due to this problem as a duplicate of this issue. By applying the fix shown below, both the Undo and Redo commands will work perfectly on both MacOS and Windows. Currently all the duplicated issues are not reproducible on Unix based operating systems such as Mac OS or Ubuntu. But on Windows 10 it will lead to the bug described above. The solution above fixes all of these issues completely.
How to replicate: 1.Add 2 types of stocks 2.use undo