-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing numberformatExceptions for European countries #47
Conversation
Fixing numberformatExceptions for European countries
I'm wordering, what problem is fixed by this PR. This problem is similar to the problem with encodings (scoverage/scalac-scoverage-plugin#112) |
When you have a JVM with a European local (for many of the european countries) the xml has the values as 12,34 instead of 12.34. xml.attribute(coverageType.paramName).toDouble() will throw a NumberFormatException when it reads a "12,34" String It seems like it is a similar problem yes, and it might be an idea to force Locale.US That change would have to be done in scalac-scoverage-plugin though and might affect the other plugins. Maybe an idea to add an extra method for the write methods that takes Locale as a parameter? |
Sorry, late to this one... From my side I think that scalac-scoverage-plugin is writing the attribute as a formatted string with the default locale, and hence it may have commas. I expect the default locale to be consistent between the JVM which is writing the XML, and the JVM which is reading it. I think the issue is that the Groovy extension I think the PR could be simplified as you don't need to pass the default locale to I'm not sure about the change to the test case as it may have unexpected effects when running tests in parallel. Finally I don't think we should force the locale of the numeric strings within the XML file; the user's locale is their choice and we should respect that. I'd like to do a little further digging into the Thanks, |
Yes, toDouble does not respect the locale.
I didn't notice that it would pick the default locale if nothing was passed, so yes will update that part of the code
I'm not to happy about that either. The issue is that the tests reads in a XML file in the test/resource folder which has numbers formated as "12.34" so those tests will fail for European JVMs
Sure, no problems for me |
@maiflai I was wondering, why I have no such problem in Scoverage Maven plugin and compared the sources. Scoverage cov = ScoverageXmlReader.read(scoverageXmlFile) statement coverage: cov.statementCoveragePercent branch coverage: cov.branchCoveragePercent line coverage written to cov.statementCoverage |
I think doing this naively will bring in a dependency on Scala 2.11, and force that dependency on every other plugin in the Gradle build script. I originally wanted to move this functionality up into the common library space as a command-line application; then execute it in a new JVM with the Scala dependencies isolated. |
I agree that it might be better if the xml files didn't contain locale-specific formatting - perhaps we could change the format string upstream to match the default Double parsing format? I think this is slightly different to picking a region such as |
We can change the format upstream. Or just lock it down to a specific On 11 November 2015 at 22:54, maiflai [email protected] wrote:
|
Hi I finally had time to analyze this problem. As @maiflai wrote above:
I agree with this, so whats the point to pass the locale to Additionally, there should be at least two tests with different locales set up, one using dots ( Again, sorry for so late comment (after a release). |
Thanks for the comments, they are much appreciated. I think I favour an upstream fix here; there is no reason for the scalac scoverage plugin to write locale-specific files. Oddly enough I think this is actually a bug I introduced: maiflai/scalac-scoverage-plugin@9daa437 If the upstream fix is accepted then we can revert to the previous behaviour which is much simpler. I've also remembered why I chose to parse the XML file; it leaves the way open for users to write their own custom assertions inside the gradle build file. I think doing it in other ways requires a more convoluted approach. |
No description provided.