How to fix Uncommented core method?

I searched for this problem through Google, but it turned out that I cannot find a way to fix this problem. In fact, I have a classic main method in which I run the task, but sonarqube continues to repeat that the found main Uncommented method was found.

Here is the code:

  /** * Main : Run MapReduce job * * @param args * arguments */ public static void main(String[] args) { ExitManager exitManager = new ExitManager(); // run job if (!runJob(args)) { exitManager.exit(1); } } 

I do not see any specific problem here, where does this problem come from? Do you know how I can fix this?

Thanks.

+5
source share
3 answers

The raw main method is a CheckStyle warning that the main() method is not commented out. You should not have debug / test main() methods in your code.

You can exclude a program entry point class using something like:

 <module name="UncommentedMain"> <property name="excludedClasses" value="\.Main$"/> </module> 

See also http://checkstyle.sourceforge.net/config_misc.html#UncommentedMain

+6
source

From the documentation :

Checks for undocumented main () methods.

Rationale: The main() method is often used for debugging purposes. When debugging is complete, developers often forget to remove this method, which changes the API and increases the size of the resulting class or JAR file. With the exception of the actual entry points to the program, all main() methods should be removed or commented out from sources.

+3
source

You can suppress the warning with @SuppressWarnings:

 @SuppressWarnings("uncommentedmain") public class YourClass { ... 
0
source

Source: https://habr.com/ru/post/1207811/


All Articles