What is package-info.java and how can I add it to my project?

Is used to store javadoc description. You can find it at 7.4.1. Named Packages of the The Java® Language Specification: It is recommended that package-info.java, if it is present, take the place of package.html for javadoc and other similar documentation generation systems. If this file is present, the documentation generation tool should look for the … Read more

Checkstyle “Method Not Designed For Extension” error being incorrectly issued?

It looks to be caused by the DesignForExtension rule. According to the documentation: Checks that classes are designed for extension. More specifically, it enforces a programming style where superclasses provide empty “hooks” that can be implemented by subclasses. The exact rule is that nonprivate, nonstatic methods of classes that can be subclassed must either be … Read more

Massively refactor – how to add final keyword to Java method argument

You can use IntelliJ’s inspections mechanism for this: Navigate to Analyze->Run Inspection by Name Search for the “Local variable or parameter can be final” warning Make sure that “Report method parameters” is the only option checked. Select the root of the tree (it should read Local variable or parameter can be final” Click ALT+ENTER and … Read more

How to get rid of Checkstyle message ‘File does not end with a newline.’

In my case that was a problem with improper configuration of that checker. By default it uses system default convention of line endings. I was working on windows and the project was using unix-style line endings. I don’t think ignoring the warning is the best strategy, so what I’ve done is: <module name=”Checker”> <module name=”NewlineAtEndOfFile”> … Read more

What does “variable access definition in wrong order” mean in Checkstyle?

Could it be that you have declaration order configured in CheckStyle? Take a look at http://checkstyle.sourceforge.net/config_coding.html#DeclarationOrder In that link, you will notice that it says … *According to Code Conventions for the Java Programming Language , the parts of a class or interface declaration should appear in the following order: Class (static) variables. First the … Read more

Why are protected variables not allowed by default in Checkstyle?

Theoretically, protected attributes (variables) are an anti-pattern in object-oriented languages. If only subclasses need to access member attributes of its superclass, define the attributes themselves as private and create protected accessor methods (getter and setter). This approach applies the concept of ‘information hiding’. There is an alternative solution: define protected immutable (final) member attributes. Further … Read more

Allowed HTML tags in Javadoc

Javadoc permits only a subset of HTML tags. Javadoc’s doclint component enforces this restriction. You can disable all doclint warnings by passing -Xdoclint:none to javadoc, though you should consider fixing your Javadoc comments because otherwise the generated HTML API documentation may look bad or may omit content. (I usually use -Xdoclint:all,-missing to get warnings about … Read more

How to generate an Eclipse formatter configuration from a checkstyle configuration?

In Eclipse (3.6): Install Checkstyle plug-in Import stylesheet using Windows –> Preferences, General –> Checkstyle –> New. Since you have an external file, choose “external file” as the type. Right-click on your project in the Package view and select Checkstyle –> Create Formatter-Profile. Then enable the formatter for your workspace: Windows –> Preferences –> Java … Read more

Intellij IDEA checkstyle

Go to the Checkstyle configuration page via File → Settings, then typing checkstyle into the search box: Press the plus icon to add your checkstyle.xml. Activate your checkstyle.xml by clicking the checkbox in the column labeled Active. That’s it! If you want real-time scans, you can go to the Inspections dialog and activate the real-time … Read more