# Settings for code duplications and how does code duplication work?

**URL:** <https://community.sonarsource.com/t/settings-for-code-duplications-and-how-does-code-duplication-work/14200>\
**Category:** SonarQube Server / Community Build\
**Tags:** duplications, configuration, sonarqube, java\
**Created:** [September 12, 2019, 8:07am UTC](https://community.sonarsource.com/t/settings-for-code-duplications-and-how-does-code-duplication-work/14200 "2019-09-12T08:07:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeslieM98](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lesliem98/32/5838_2.png) [@LeslieM98](https://community.sonarsource.com/u/LeslieM98)\
**Post date:** [September 12, 2019, 8:07am UTC](https://community.sonarsource.com/t/settings-for-code-duplications-and-how-does-code-duplication-work/14200/1 "2019-09-12T08:07:33Z")

</div>

When having the below 2 classes, Teamscale tells me at least the code fragment ranging from private final int a; until the last } in the second if statement of the equals method are definetly duplicates. In SonarQube it tells me there is no duplication at all. Why is it like that?

I read up on the topic but could not find that much detailed docs, it states a fragment has to have at least 10 duplicated statements to be recognized as duplicate. What does count as a statement? When I count in the Methodheads it is more than 10 otherwise less than 10. Can I adjust this value? Also can I adjust this value for a specific package without changing it for others?

```
public class A
{
    private final int a;

    public A(final int a)
    {
        this.a = a;
    }

    public int getA()
    {
        return a;
    }

    @Override
    public boolean equals(Object other)
    {
        if (other == null)
        {
            return false;
        }

        if (this.getClass() != other.getClass())
        {
            return false;
        }

        A otherA = (A) other;

        return a == otherA.a;
    }
}

public class B{

    private final int b;

    public B(final int b)
    {
        this.b = b;
    }

    public int getB()
    {
        return b;
    }

    @Override
    public boolean equals(Object other)
    {
        if (other == null)
        {
            return false;
        }

        if (this.getClass() != other.getClass())
        {
            return false;
        }

        B otherB = (B) other;

        return b == otherB.b;
    }
}
```

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [September 16, 2019, 1:36pm UTC](https://community.sonarsource.com/t/settings-for-code-duplications-and-how-does-code-duplication-work/14200/2 "2019-09-16T13:36:42Z")

</div>

Hi,

We crafted our own duplication detection engine, so it’s not surprising that you get a different result in other tools. It may help to take a look at the language-specific details for the [Metric definition for duplications](https://docs.sonarqube.org/latest/user-guide/metric-definitions/#header-3).

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![LeslieM98](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lesliem98/32/5838_2.png) [@LeslieM98](https://community.sonarsource.com/u/LeslieM98)\
**Post date:** [September 17, 2019, 8:28am UTC](https://community.sonarsource.com/t/settings-for-code-duplications-and-how-does-code-duplication-work/14200/3 "2019-09-17T08:28:22Z")

</div>

Hi,  
I’m not really sure where I can change those values. Also would it be possible to adjust those values based on in which folder those files are? F.e. Files in com.example.my-classes should have a threshold of 15 statements where com.example.my-abstract-classes should have a threshold of 10.

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [September 17, 2019, 11:18am UTC](https://community.sonarsource.com/t/settings-for-code-duplications-and-how-does-code-duplication-work/14200/4 "2019-09-17T11:18:27Z")

</div>

Hi,

For tuning the values, take a look at the `sonar.cpd.*` [analysis parameters](https://docs.sonarqube.org/latest/analysis/analysis-parameters/). You can do this on an analysis-wide basis but not at a directory level.

&nbsp;  
HTH,  
Ann

---

<div class="post-metadata">

**Author:** ![felipebz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/felipebz/32/32739_2.png) [@felipebz](https://community.sonarsource.com/u/felipebz)\
**Post date:** [September 17, 2019, 11:29am UTC](https://community.sonarsource.com/t/settings-for-code-duplications-and-how-does-code-duplication-work/14200/5 "2019-09-17T11:29:57Z")

</div>

Please note that the `sonar.cpd.*` parameters are not used by the Java plugin.

> [@Java project - duplicates](https://community.sonarsource.com/t/java-project-duplicates/13955/2):
>
> For Java, there’s indeed a threshold of 10 statements but you cannot change it according to [the documentation](https://docs.sonarqube.org/latest/analysis/analysis-parameters/).
