Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Test failed due to locale message settings. (with non-English locale settings) #3896
With a non-English locale settings (in my case is zh-CN), running CheckerTest#testHaltOnExceptionOff will assert an error as following:
The difference is between
And the configuration is loaded by LocalizedMessage. We can set the locale manually by LocalizedMessage#setLocale and this method is called by Checker. I thought setting the locale in the test method should solve the bug.
So back to the error itself. In method
and the test in Intellij turns green after that.
But the same error still occurs when I run
That's the most effort I could do by now. I don't know what to do next.
as you have "zh-CN", java suppose to load "_zh.properties" files.
@Luolc , please try to do copy-paste of _zh.properties to _zh-CN.properties and look in debug what files java is expected to load for your locale.
it is not clear why CI for ("zh") is not failing - https://travis-ci.org/checkstyle/checkstyle/jobs/206991113
I don't think the zh CI should pass.
The expected error message is hard coded
Test failure could be related to Issue #3377.
I find the reason eventually.
Firstly, a way to reproduce the bug is mentioned in Issue #3377 . As MEZk suggested, I add a
The different behavior between Intellij test and command line
So the bug is due to the cache of resource bundle. https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java#L301-L305
And it is funny that if I add
to the first method of
I add a line to clear the BUNDLE_CACHE when setting a different locale at https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java#L363
I think we need to handle the cache problem and then fix the bugs in
This change looks valid to me. The cache is built upon this value, so if it changes, then so should the cache. IMO, I see no problem erasing the cache if the locale changes.
Should we watch out for class loader changes or just ignore this as we are dropping class loader from
I am going to work on it :)