title: How to avoid sonarqube marking a code region as duplicate which is not a (harmful) repetition?
body: <p>I have the following code setup (not all parts are shown in detail):</p>
  
  <ul>
  <li><code>ClassInterface</code> and its abstract implementation <code>AbstractClassToBuild</code></li>
  <li><code>BuilderInterface</code> and its abstract implementation <code>AbstractBuilder</code></li>
  </ul>
  
  <p>There are <em>several specific implementations of AbstractClassToBuild</em> based on
  different object types.</p>
  
  <p>A <em>simplified example</em> of such an iplementation is the following <em>ClassToBuild</em>. 
  The relevant region which is marked as duplicate by sonarqube for all implementations looks the same for all of these implementations. The following code snippet uses comments to highlight the relevant region:</p>
  
  <pre><code>public final ClassToBuild extends AbstractClassToBuild {
  
  // ... whatever belongs to the class ClassToBuild
  
  // START OF DUPLICATE REGION
  public static final class Builder extends AbstractBuilder {
  
  private Builder() {
  super();
  }
  
  private Builder(Object object) {
  super(object);
  }
  
  public static final Builder newInstance() {
  return new Builder();
  }
  
  @Override
  public final BuilderInterface cloneInstance() {
  return new Builder(this.object);
  }
  
  @Override
  @SuppressWarnings("unchecked")
  protected final &lt;T extends ClassInterface&gt; Class&lt;T&gt; myClass() {
  // END OF DUPLICATE REGION
  return (Class&lt;T&gt;) ClassToBuild.class;
  }
  
  @Override
  protected final ClassInterface create() {
  return new ClassToBuild(this.object);
  }
  }
  
  }
  </code></pre>
  
  <p><em>IMHO</em> this kind of scenario is a <em>valid, non-repetitive implementation</em> 
  as there is <strong>no real (harmful) code duplication</strong> because each Builder class 
  belongs to a specific class. Please correct me if you smell a design or implementation issue here.</p>
  
  <p>Technical setup:</p>
  
  <ul>
  <li>sonarqube server version 6.2 with Java plugin 4.4</li>
  <li>Oracle JDK 1.8u121</li>
  </ul>
  
  <p><strong>Anyways, what can be done to prevent sonarqube marking these regions as duplicate?</strong></p>
  
  <hr>
  
  <p><strong>Addition:</strong></p>
  
  <p><a href="https://docs.sonarqube.org/display/HOME/Duplications" rel="nofollow noreferrer">According to the sonarqube documentation</a>:</p>
  
  <p>"A piece of code is considered as duplicated as soon as there is the same sequence of 10 successive statements whatever the number of tokens and lines."</p>
  
  <p>and the <a href="https://docs.sonarqube.org/display/SONAR/Metrics+-+Statements" rel="nofollow noreferrer">explanation of what a (java) statement is</a>:</p>
  
  <p>"Number of statements as defined in the Java Language Specification but without block definitions. Statements counter gets incremented by one each time a following keyword is encountered: if, else, while, do, for, switch, break, continue, return, throw, synchronized, catch, finally.
  Statements counter is not incremented by a class, method, field, annotation definition, package declaration and import declaration."</p>
  
  <p>With this, for me an additional question comes up: <strong>Does sonarqube mark these region as duplicate by mistake?</strong></p>