{"id":610,"date":"2019-10-25T09:00:14","date_gmt":"2019-10-25T09:00:14","guid":{"rendered":"http:\/\/www.yebeeniii.site\/?p=610"},"modified":"2020-02-08T14:52:50","modified_gmt":"2020-02-08T14:52:50","slug":"sonarcube","status":"publish","type":"post","link":"http:\/\/happily70.dothome.co.kr\/?p=610","title":{"rendered":"sonarcube"},"content":{"rendered":"\n<p>sonarcube\ub294 <br>\uc9c0\uc18d\uc801\uc73c\ub85c \ucf54\ub4dc\uc758 \ud488\uc9c8\uc744 \ub192\uc774\uace0 \uc720\uc9c0 \ubcf4\uc218\ud558\ub294\ub370 \ub3c4\uc6c0\uc744 \uc8fc\ub294 \uc815\uc801 \ubd84\uc11d \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc73c\ub85c \ubd84\uc11d \uae30\ub2a5\uc774 \ud0c1\uc6d4\ud558\uace0 \uac1c\uc120 \uc0ac\ud56d\ub3c4 \uc790\uc138\ud558\uac8c \uc548\ub0b4\ud574 \uc900\ub2e4. <br>\uac04\ub2e8\ud558\uac8c\ub294 \ucf54\ub529 \ucee8\ubca4\uc158\ubd80\ud130 \ucf54\ub4dc\uc758 \uc7a0\uc7ac\uc801\uc778 \uc704\ud5d8 \uc0ac\ud56d\uae4c\uc9c0 \uc548\ub0b4\ud574\uc8fc\uc5b4 \uc62c\ubc14\ub978 \ucf54\ub529 \uc2b5\uad00\uacfc \ucf54\ub4dc\uc758 \ud488\uc9c8\ud5a5\uc0c1\uc5d0 \ub9ce\uc740 \ub3c4\uc6c0\uc744 \uc900\ub2e4.<\/p>\n\n\n\n<p><strong>\ub2e4\uc6b4\ub85c\ub4dc \ubc0f \uc124\uce58<\/strong><br><a rel=\"noreferrer noopener\" href=\"https:\/\/www.sonarqube.org\/downloads\/\" target=\"_blank\">https:\/\/www.sonarqube.org\/downloads\/<\/a> \uc5d0\uc11c \ub2e4\uc6b4\ub85c\ub4dc \ubc1b\uace0 \uc555\ucd95\uc744 \ud574\uc81c.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">issue 1.&nbsp;<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Either log or rethrow this exception (5)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause :&nbsp;When handling a caught exception, the original exception&#8217;s message and stack trace should be logged or passed forward.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr>\n<th>noncompliant code example\ufeff<\/th>\n<\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n\/\/ Noncompliant - exception is lost <br\/>\ntry { <br\/>\n  \/* ... *\/<br\/>\n} catch (Exception e) {<br\/>\n  LOGGER.info(\"context\");<br\/>\n}<br\/><br\/>\n\/\/ Noncompliant - exception is lost (only message is preserved)<br\/>\ntry { <br\/>\n  \/* ... *\/<br\/>\n} catch (Exception e) {<br\/>\n  LOGGER.info(e.getMessage());<br\/>\n}<br\/><br\/>\n\/\/ Noncompliant - exception is lost<br\/>\ntry { <br\/>\n  \/* ... *\/<br\/>\n} catch (Exception e) {<br\/>\n  throw new RuntimeException(\"context\"); <br\/>\n}<br\/>\n<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<th>compliant code example\ufeff<\/th>\n<\/tr>\n<tr><td>\n<pre class=\"prettyprint\">\ntry { <br\/> \n  \/* ... *\/ <br\/>\n} catch (Exception e) { <br\/>\n  LOGGER.info(e); <br\/>\n}<br\/><br\/>\ntry { <br\/>\n  \/* ... *\/<br\/>\n} catch (Exception e) {<br\/>\n throw new RuntimeException(e); <br\/>\n}<br\/>\n<br\/>\ntry {<br\/>\n  \/* ... *\/<br\/>\n} catch (RuntimeException e) {<br\/>\n  doSomething();<br\/>\n  throw e;<br\/>\n} catch (Exception e) {<br\/>\n  \/\/ Conversion into unchecked exception is also allowed<br\/>\n  throw new RuntimeException(e);<br\/>\n}<\/pre>\n<\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 2.&nbsp;<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Define and throw a dedicated exception instead of using a generic one&nbsp;(7)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;:&nbsp;Using such generic exceptions as&nbsp;<code>Error<\/code>,&nbsp;<code>RuntimeException<\/code>,&nbsp;<code>Throwable<\/code>, and&nbsp;<code>Exception<\/code>&nbsp;prevents calling methods from handling true, system-generated exceptions differently than application-generated errors.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic void foo(String bar) throws Throwable {  \/\/ Noncompliant <br\/>\n  throw new RuntimeException(\"My Message\");     \/\/ Noncompliant <br\/>\n}<\/pre>\n<\/td>\n<\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic void foo(String bar) { <br\/>\n throw new MyOwnRuntimeException(\"My Message\"); <br\/>\n}\n<\/pre>\n<\/td><\/tr><\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 3.&nbsp;<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Use isEmpty() to check whether the collection is empty or not.&nbsp;(1)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;:&nbsp;Using&nbsp;<code>Collection.size()<\/code>&nbsp;to test for emptiness works, but using&nbsp;<code>Collection.isEmpty()<\/code>&nbsp;makes the code more readable and can be more performant. The time complexity of any&nbsp;<code>isEmpty()<\/code>&nbsp;method implementation should be&nbsp;<code>O(1)<\/code>&nbsp;whereas some implementations of&nbsp;<code>size()<\/code>&nbsp;can be&nbsp;<code>O(n)<\/code>.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nif (myCollection.size() == 0) {  \/\/ Noncompliant <br\/>\n  \/* ... *\/ <br\/>\n}\n<\/pre>\n<\/td>\n<\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nif (myCollection.isEmpty()) { <br\/>\n  \/* ... *\/ <br\/>\n}\n<\/pre>\n<\/td>\n<\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 4.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Move the &#8220;update&#8221; string literal on the left side of this string comparison.<\/h5>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nString myString = null;<br\/><br\/>\nSystem.out.println(\"Equal? \" + myString.equals(\"foo\"));<br\/>\n\/\/ Noncompliant; will raise a NPE<br\/><br\/>\nSystem.out.println(\"Equal? \" + (myString != null &amp;&amp; myString.equals(\"foo\")));  <br\/>\n\/\/ Noncompliant; null check could be removed\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nSystem.out.println(\"Equal?\" + \"foo\".equals(myString)); <br\/>                       \/\/ properly deals with the null case <br\/>\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 5.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Merge this if statement with the enclosing one.&nbsp;(4)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;:&nbsp;Merging collapsible&nbsp;<code>if<\/code>&nbsp;statements increases the code&#8217;s readability.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nif (file != null) { <br\/>\n  if (file.isFile() || file.isDirectory()) { <br\/>\n    \/* ... *\/ <br\/>\n  } <br\/>\n}\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nif (file != null && isFileOrDirectory(file)) { <br\/>\n  \/* ... *\/ <br\/>\n} <br\/>\nprivate static boolean isFileOrDirectory(File file) { <br\/>\n  return file.isFile() || file.isDirectory();<br\/>\n}<br\/>\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 6.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Remove this unused &#8220;\ubcc0\uc218\uba85&#8221;&nbsp;&nbsp;(33)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;: If a private field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will improve maintainability because developers will not wonder what the variable is used for.&nbsp;(\uc8fc\ub85c&nbsp;\ub3c4\uba54\uc778 \uac1d\uccb4)<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic class MyClass {<br\/>\n  private int foo = 42;<br\/>\n<br\/>\n  public int compute(int a) {<br\/>\n    return a * 42;<br\/>\n  }<br\/>\n}\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic class MyClass {<br\/>\n   public int compute(int a) { <br\/>\n      return a * 42;<br\/>\n   }<br\/>\n}\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 7.&nbsp;<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">The Cyclomatic Complexity of this method \uba54\uc18c\ub4dc\uba85.&nbsp;(9)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\" style=\"text-align:left\">&nbsp;&#8211; cause&nbsp;: The cyclomatic complexity of methods should not exceed a defined threshold.&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Complex code can perform poorly and will in any case be difficult to understand and therefore to maintain.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n-\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n-\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 8.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">duplicated blocks of code must be removed.&nbsp;(3)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;:&nbsp;An issue is created on a file as soon as there is at least one block of duplicated code on this file.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n-\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n-\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 9.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">The type of the &#8220;input&#8221; object should be an interface such as &#8220;Map&#8221; rather than the implementation &#8220;HashMap&#8221;.&nbsp;(2)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;: The purpose of the Java Collections API is to provide a well defined hierarchy of interfaces in order to hide implementation details.<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp; Implementing classes must be used to instantiate new collections, but the result of an instantiation should ideally be stored in a variable whose type is a Java Collection interface.<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">\u00a0 This rule raises an issue when an implementation class:<\/h6>\n\n\n\n<ul class=\"wp-block-list\"><li>is returned from a&nbsp;<code>public<\/code>&nbsp;method.<\/li><li>is accepted as an argument to a&nbsp;<code>public<\/code>&nbsp;method.<\/li><li>is exposed as a&nbsp;<code>public<\/code>&nbsp;member.<\/li><\/ul>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic class Employees { <br\/>\n  private HashSet&lt;Employee&gt; employees = new HashSet&lt;Employee&gt;();  <br\/>\/\/ Noncompliant - \"employees\" should have type \"Set\" rather than \"HashSet\"<br\/><br\/>\n\n  public HashSet&lt;Employee&gt; getEmployees() {  \/\/ Noncompliant <br\/>\n    return employees;<br\/>\n  }<br\/>\n}<br\/>\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic class Employees {  <br\/>\n private Set<Employee> employees = new HashSet<Employee>();  \/\/ Compliant<br\/>\npublic Set<Employee> getEmployees() { \/\/ Compliant <br\/>     \nreturn employees;<br\/>\n   }<br\/>\n }\n<\/pre><\/td><\/tr>\n<\/table> \n\n\n\n<h4 class=\"wp-block-heading\">issue 10.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Reduce the number of conditional operators {:num} used in the expression (maximum allowed :num).&nbsp;(3)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;: The complexity of an expression is defined by the number of&nbsp;<code>&amp;&amp;<\/code>,&nbsp;<code>||<\/code>&nbsp;and&nbsp;<code>condition ? ifTrue : ifFalse<\/code>&nbsp;operators it contains.&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A single expression&#8217;s complexity should not become too high to keep the code readable.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nWith the default threshold value of 3: <br\/>\nif (((condition1 && condition2) || (condition3 && condition4)) && condition5) {<br\/>\n ... <br\/>\n}\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nif ( (myFirstCondition() || mySecondCondition()) && myLastCondition()) {<br\/> ... <br\/>}\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 11.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Method has {:num}&nbsp;parameters, which is greater than {:num} authorized.&nbsp;(3)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;:&nbsp;A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nWith a maximum number of 4 parameters:<br\/>\npublic void doSomething(int param1, int param2, int param3, String param4, long param5) {<br\/>\n ...<br\/>\n}\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic void doSomething(int param1, int param2, int param3, String param4) {<br\/>\n ... <br\/>\n}\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 12.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Refactor this code to not nest more than 3 if\/for\/while\/switch\/try statements.&nbsp;(3)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;: Nested&nbsp;<code>if<\/code>,&nbsp;<code>for<\/code>,&nbsp;<code>while<\/code>,&nbsp;<code>switch<\/code>, and&nbsp;<code>try<\/code>&nbsp;statements is a key ingredient for making what&#8217;s known as &#8220;Spaghetti code&#8221;.&nbsp;Such code is hard to read, refactor and therefore maintain.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nWith the default threshold of 3: <br\/>\nif (condition1) { \/\/ Compliant - depth = 1  <br\/> \n  \/* ... *\/   <br\/>\n  if (condition2) { \/\/ Compliant - depth = 2  <br\/>\n    \/* ... *\/   <br\/>\n    for(int i = 0; i < 10; i++) {  \/\/ Compliant - depth = 3, not exceeding the limit <br\/>\n       \/* ... *\/ <br\/>       \n       if (condition4) {  \/\/ Noncompliant - depth = 4  <br\/>       \n          if (condition5) {  \/\/ Depth = 5, exceeding the limit, but issues are only reported on depth = 4 <br\/>        \n  \/* ... *\/  <br\/>      \n} <br\/>\n return; <br\/>      \n} <br\/> } <br\/> } <br\/>}\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n-\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 13.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Complete the task associated to this TODO comment.&nbsp;&nbsp;(2)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&nbsp;&#8211; cause&nbsp;:&nbsp;<code>TODO<\/code>&nbsp;tags are commonly used to mark places where some more code is required, but which the developer wants to implement later.<br>Sometimes the developer will not have the time or will simply forget to get back to that tag.&nbsp;<br>This rule is meant to track those tags, and ensure that they do not go unnoticed.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nvoid doSomething() {   \/\/ TODO }\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n-\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 14. issue 15. issue 16. issue 17.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Document this public class.&nbsp;&nbsp;(17)<br>Document the parameter(s): page. (16)<br>Document this public interface. (5)<br>Document this public method. (70)<br>Document this public enum. (5)<br>Document this public constructor. (5)&nbsp;<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&#8211; cause : Try to imagine using the standard Java API (Collections, JDBC, IO, &#8230;) without Javadoc. It would be a nightmare, because Javadoc is the only way to understand of the contract of the API. Documenting an API with Javadoc increases the productivity of the developers consuming it.<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">The following Javadoc elements are required:<\/h6>\n\n\n\n<ul class=\"wp-block-list\"><li>Parameters, using&nbsp;<code>@param parameterName<\/code>.<\/li><li>Method return values, using&nbsp;<code>@return<\/code>.<\/li><li>Generic types, using&nbsp;<code>@param &lt;T&gt;<\/code>.<\/li><\/ul>\n\n\n\n<h6 class=\"wp-block-heading\">The following public methods and constructors are not taken into account by this rule:<\/h6>\n\n\n\n<ul class=\"wp-block-list\"><li>Getters and setters.<\/li><li>Methods with @Override annotation.<\/li><li>Empty constructors.<\/li><li>Static constants.<\/li><\/ul>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n\/**<br\/>\n * This is a Javadoc comment<br\/>\n *\/<br\/>\npublic class MyClass<T> implements Runnable { \/\/ Noncompliant - missing '@param <T>'  <br\/>\n public static final DEFAULT_STATUS = 0; \/\/ Compliant - static constant<br\/>\n private int status;     \/\/ Compliant - not public <br\/>\n public String message;  \/\/ Noncompliant   <br\/>\n public MyClass() {      \/\/ Noncompliant - missing documentation <br\/>  \n   this.status = DEFAULT_STATUS;<br\/>\n }<br\/><br\/>\n\n public void setStatus(int status) {  \/\/ Compliant - setter  <br\/>\n   this.status = status; <br\/>\n }<br\/><br\/>   \n\n@Override<br\/>\npublic void run() {  \/\/ Compliant - has @Override annotation   } <br\/>  protected void doSomething() {    \/\/ Compliant - not public   } <br\/>  public void doSomething2(int value) {  \/\/ Noncompliant   } <br\/>\npublic int doSomething3(int value) {  \/\/ Noncompliant  <br\/>\n   return value;<br\/>\n}<br\/> \n}\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\n\/** <br\/>\n * This is a Javadoc comment   <br\/>\n * @param <T> ...   <br\/>\n *\/<br\/>\npublic class MyClass<T> implements Runnable {<br\/>\n   public static final DEFAULT_STATUS = 0;<br\/>\n   private int status;<br\/>\n   \/**<br\/>\n     * This is a Javadoc comment<br\/>\n     *\/<br\/>\n   public String message;<br\/><br\/>\n   \/**<br\/>\n    * Class comment...<br\/>\n    *\/<br\/>\n   public MyClass() {<br\/>\n     this.status = DEFAULT_STATUS;<br\/>\n   }<br\/>\n   public void setStatus(int status) { <br\/>\n    this.status = status;<br\/>\n   }<br\/><br\/>\n   @Override<br\/>\n   public void run() {   }<br\/>\n   protected void doSomething() {   }<br\/>\n   \/**<br\/>\n     * @param value ... <br\/>    \n     *\/<br\/>\n   public void doSomething(int value) {<br\/>\n   \/**<br\/>\n     *  {@inheritDoc}<br\/>\n     *\/<br\/>\n   public int doSomething(int value) {<br\/>\n     return value;<br\/>\n   }<br\/>\n }\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 18.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Immediately return this expression instead of assigning it to the temporary variable (5)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&#8211; cause : Declaring a variable only to immediately return or throw it is a bad practice.<br>Some developers argue that the practice improves code readability, because it enables them to explicitly name what is being returned. However, this variable is an internal implementation detail that is not exposed to the callers of the method. The method name should be sufficient for callers to know exactly what will be returned.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic long computeDurationInMilliseconds() {<br\/>\n   long duration = (((hours * 60) + minutes) * 60 + seconds ) * 1000;<br\/>  return duration;<br\/>\n}<br\/><br\/>\npublic void doSomething() {<br\/>\n   RuntimeException myException = new RuntimeException();<br\/>\n   throw myException; <br\/>\n}\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic long computeDurationInMilliseconds() {<br\/>\n   return (((hours * 60) + minutes) * 60 + seconds ) * 1000 ; <br\/>\n}<br\/><br\/>\npublic void doSomething() {<br\/>\n   throw new RuntimeException(); <br\/>\n}\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 19.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Define a constant instead of duplicating this literal &#8220;{:variable name}&#8221; {:num} times.&nbsp;(9)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&#8211; cause : Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.<br>On the other hand, constants can be referenced from many places, but only need to be updated in a single place.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic void run() { <br\/>\n  prepare(\"action1\"); \/\/ Noncompliant - \"action1\" is duplicated 3 times <br\/>execute(\"action1\");<br\/>  release(\"action1\"); <br\/>\n}<br\/>\n@SuppressWarning(\"all\") \/\/ Compliant - annotations are excluded<br\/> private void method1() {<br\/>\n \/* ... *\/<br\/>\n}<br\/><br\/>\n@SuppressWarning(\"all\") <br\/>\nprivate void method2() {<br\/>\n \/* ... *\/<br\/>\n}<br\/><br\/>\npublic String method3(String a) {<br\/>\n   System.out.println(\"'\" + a + \"'\"); \/\/ Compliant - literal \"'\" has less than 5 characters and is excluded<br\/>\n   return \"\"; \/\/ Compliant - literal \"\" has less than 5 characters and is excluded <br\/>\n}\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nprivate static final String ACTION_1 = \"action1\";  \/\/ Compliant <br\/>\npublic void run() { <br\/>\n  prepare(ACTION_1);  \/\/ Compliant <br\/>\n  execute(ACTION_1);  <br\/>\n  release(ACTION_1); <br\/>\n}\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 20.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">At most one statement is allowed per line, but&nbsp;{:num}&nbsp;statements were found on this line.&nbsp;(3)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&#8211; cause : For better readability, do not put more than one statement on a single line.<\/h6>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nif(someCondition) doSomething();\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nif(someCondition) {   doSomething(); }\n<\/pre><\/td><\/tr>\n<\/table>\n\n\n\n<h4 class=\"wp-block-heading\">issue 21.<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Reorder the modifiers to comply with the Java Language Specification.&nbsp;&nbsp;(22)<\/h5>\n\n\n\n<h6 class=\"wp-block-heading\">&#8211; cause : The Java Language Specification recommends listing modifiers in the following order:<\/h6>\n\n\n\n<p>1. Annotations<br>2. public<br>3. protected<br>4. private<br>5. abstract<br>6. static<br>7. final<br>8. transient<br>9. volatile<br>10. synchronized<br>11. native<br>12. strictfp<br>Not following this convention has no technical impact, but will reduce the code&#8217;s readability because most developers are used to the standard order.<\/p>\n\n\n\n<table class=\"sonarcube\">\n<tr><th>noncompliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\nstatic public void main(String[] args) {   \/\/ Noncompliant }\n<\/pre><\/td><\/tr>\n<tr><th>compliant code example\ufeff<\/th><\/tr>\n<tr>\n<td>\n<pre class=\"prettyprint\">\npublic static void main(String[] args) {   \/\/ Compliant }\n<\/pre><\/td><\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>sonarcube\ub294 \uc9c0\uc18d\uc801\uc73c\ub85c \ucf54\ub4dc\uc758 \ud488\uc9c8\uc744 \ub192\uc774\uace0 \uc720\uc9c0 \ubcf4\uc218\ud558\ub294\ub370 \ub3c4\uc6c0\uc744 \uc8fc\ub294 \uc815\uc801 \ubd84\uc11d \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc73c\ub85c \ubd84\uc11d \uae30\ub2a5\uc774 \ud0c1\uc6d4\ud558\uace0 \uac1c\uc120 \uc0ac\ud56d\ub3c4 \uc790\uc138\ud558\uac8c \uc548\ub0b4\ud574 \uc900\ub2e4. \uac04\ub2e8\ud558\uac8c\ub294 \ucf54\ub529 \ucee8\ubca4\uc158\ubd80\ud130 \ucf54\ub4dc\uc758 \uc7a0\uc7ac\uc801\uc778 \uc704\ud5d8 \uc0ac\ud56d\uae4c\uc9c0 \uc548\ub0b4\ud574\uc8fc\uc5b4 \uc62c\ubc14\ub978 \ucf54\ub529 \uc2b5\uad00\uacfc \ucf54\ub4dc\uc758 \ud488\uc9c8\ud5a5\uc0c1\uc5d0 \ub9ce\uc740 \ub3c4\uc6c0\uc744 \uc900\ub2e4. \ub2e4\uc6b4\ub85c\ub4dc \ubc0f \uc124\uce58https:\/\/www.sonarqube.org\/downloads\/ \uc5d0\uc11c \ub2e4\uc6b4\ub85c\ub4dc \ubc1b\uace0 \uc555\ucd95\uc744 \ud574\uc81c. issue 1.&nbsp; Either log or rethrow this exception (5) &nbsp;&#8211; cause<\/p>\n<footer class=\"entry-footer index-entry\">\n<div class=\"post-social pull-left\"><a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=http%3A%2F%2Fhappily70.dothome.co.kr%2F%3Fp%3D610\" target=\"_blank\" class=\"social-icons\"><i class=\"fa fa-facebook\" aria-hidden=\"true\"><\/i><\/a><a href=\"https:\/\/twitter.com\/home?status=http%3A%2F%2Fhappily70.dothome.co.kr%2F%3Fp%3D610\" target=\"_blank\" class=\"social-icons\"><i class=\"fa fa-twitter\" aria-hidden=\"true\"><\/i><\/a><a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=http%3A%2F%2Fhappily70.dothome.co.kr%2F%3Fp%3D610&#038;title=sonarcube\" target=\"_blank\" class=\"social-icons\"><i class=\"fa fa-linkedin\" aria-hidden=\"true\"><\/i><\/a><\/div>\n<p class=\"link-more\"><a href=\"http:\/\/happily70.dothome.co.kr\/?p=610\" class=\"more-link\">Continue reading <span class=\"meta-nav\">\u2192<\/span><\/a><\/p>\n<\/footer>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,33],"tags":[],"class_list":["post-610","post","type-post","status-publish","format-standard","hentry","category-back-end","category-developement"],"_links":{"self":[{"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/610"}],"collection":[{"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=610"}],"version-history":[{"count":14,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/610\/revisions"}],"predecessor-version":[{"id":744,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/610\/revisions\/744"}],"wp:attachment":[{"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=610"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/happily70.dothome.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}