Skip to content
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

Checker.localeLanguage property work strange with system property user.language #12101

Closed
rnveach opened this issue Aug 25, 2022 · 2 comments
Closed

Comments

@rnveach
Copy link
Member

rnveach commented Aug 25, 2022

https://checkstyle.org/config.html#Checker_Properties

$ cat TestClass.java
public class TestABbreviation {}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name = "Checker">
  <property name="charset" value="UTF-8"/>
  <property name="localeLanguage" value="fr"/> <!-- ATTENTION HERE -->

  <property name="severity" value="warning"/>

  <property name="fileExtensions" value="java, properties, xml"/>

  <module name="TreeWalker">
    <module name="AbbreviationAsWordInName">
      <property name="ignoreFinal" value="false"/>
      <property name="allowedAbbreviationLength" value="0"/>
      <property name="allowedAbbreviations" value="AB"/>
      <property name="tokens"
               value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
                    PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF,
          RECORD_COMPONENT_DEF"/>
    </module>
  </module>
</module>

$ java -jar checkstyle-10.3.2-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[WARN] M:\\Test.java:1:14: L'abréviation dans le nom 'TestABbreviation' ne doit pas 
      contenir plus de '1' lettres majuscules. [AbbreviationAsWordInName]
Audit done.

$ java -D"user.language=fr" -jar .\checkstyle-10.3.2-all.jar -c Test.xml Test.java
Début de la vérification...
[WARN] M:\\Test.java:1:14: L'abréviation dans le nom 'TestABbreviation' ne doit pas 
     contenir plus de '1' lettres majuscules. [AbbreviationAsWordInName]
Vérification terminée.

Starting audit doesn't obey config locale while check messages do.
I expect both outputs to be exactly the same since the configuration file specifies the language, but it turns out starting/finishing audits is in the OS language which for me is English.

Issue is DefaultLogger is only using the default locale
https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/DefaultLogger.java#L233

Migration notes for plugins:
please recheck code changes in api/Violation.java and how locale should be set.

@rnveach
Copy link
Member Author

rnveach commented Aug 26, 2022

There is a secondary issue where we don't initialize new locale right away. Exceptions and probably other things who try to print localized messages will use the default locale before it is actually initialized from the config and will result in a similar issue.
https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/Checker.java#L433

While we can't always guarantee this, it is just something else to consider.

rnveach added a commit to rnveach/checkstyle that referenced this issue Aug 26, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Aug 26, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Aug 26, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Aug 26, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Aug 28, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Aug 28, 2022
@checkstyle checkstyle deleted a comment from nrmancuso Sep 23, 2022
@checkstyle checkstyle deleted a comment from rnveach Sep 23, 2022
@romani romani changed the title Starting audit doesn't obey config locale while check messages do Checker.localeLanguage property work strange with system property user.language Sep 23, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Sep 25, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Sep 25, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Sep 26, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Sep 26, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Oct 9, 2022
rnveach added a commit to rnveach/checkstyle that referenced this issue Oct 9, 2022
@nrmancuso
Copy link
Member

Closed via #12105

@romani romani added this to the 10.4 milestone Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants