Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix an Uncommented main method?

I have been looking for this problem through google but it turns out I can not find a way to fix this problem. Actually I have a classic main method in which I run a job, but sonarqube keeps repeating me there is an Uncommented main method 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 particular problem here, so where does this problem come from ? Do you have any idea how I can fix this ?

Thanks.

like image 764
hacks4life Avatar asked Nov 27 '14 14:11

hacks4life


2 Answers

Uncommented main method is a CheckStyle warning that the main() method is not commented-out. You are not supposed to have debug/test main() methods in your code.

You can exclude your 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

like image 55
Vlad Avatar answered Sep 17 '22 15:09

Vlad


From the documentation:

Checks for uncommented main() methods.

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

like image 32
Jens Avatar answered Sep 19 '22 15:09

Jens