-1

I am trying to use ListResourceBundle for localizing my web app. It works well but checkstyle shows warning

public class Locale_en_US extends ListResourceBundle {
     @Override
     protected final Object[][] getContents() {
         return new Object[][]{
                 {"Login.Enter-with", "Enter with"},
                 {"Login.Hello", "Hello"},
                 {"Login.Test-Description", "You will have 40 minutes after "
                        + "starting test, to finish it"}
       };
   }
}

And after use it:

ResourceBundle resourceBundle = ResourceBundle.getBundle("Locale",request.getLocale());
String testDescr=resourceBundle.getString("Login.Test-Description")

"Name 'Locale_en_US' must match pattern '^[A-Z][a-zA-Z0-9]*$'.".

Is where any way to fix this except of changing checkstyle ruleset?

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
  • Welcome to Stack Overflow. I edited your post. I marked down a keyword using two asterisks. And I marked down your error using > I think you need to show us more of you code, style sheet etc. – Rohit Gupta Oct 22 '15 at 04:29
  • Can you add some code? I don't know what I can help you. – Thanh Duy Ngo Oct 22 '15 at 04:33

2 Answers2

0

Actually, i found solution: I created property file "Locale_en.properties" with content:

Login.Enter-with=Enter with
Login.Hello=Hello
Login.Test-Description=You will have 40 minutes after starting test to finish it

And then changed to

ResourceBundle.getBundle("/Locale",request.getLocale())

Now it works same way, but it doesn't require use of class.

P.S. sorry for my broken english.

0

I added the SuppressWithNearbyCommentFilter to the checkstyle configuration:

<module name="TreeWalker">
    <module name="SuppressWithNearbyCommentFilter">
        <property name="commentFormat" value="CHECKSTYLE IGNORE THIS LINE"/>
        <property name="checkFormat" value=".*"/>
        <property name="influenceFormat" value="0"/>
    </module>
    <module name="OuterTypeFilename"/>

Then it is easy to ignore the warnings:

public class DemoClass_DT { // CHECKSTYLE IGNORE THIS LINE
  private static final org.slf4j.Logger logger =
          org.slf4j.LoggerFactory.getLogger(DemoClass_DT.class);

  private LocalDate D; // CHECKSTYLE IGNORE THIS LINE
  private int [] array;
}

This works with checkstyle 8.41.1.

wnck
  • 11
  • 3