# Java: "duplicated blocks of code" rule for native methods

**URL:** <https://community.sonarsource.com/t/java-duplicated-blocks-of-code-rule-for-native-methods/23507>\
**Category:** SonarQube Cloud\
**Tags:** java\
**Created:** [April 22, 2020, 7:54pm UTC](https://community.sonarsource.com/t/java-duplicated-blocks-of-code-rule-for-native-methods/23507 "2020-04-22T19:54:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bullet-tooth](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@bullet-tooth](https://community.sonarsource.com/u/bullet-tooth)\
**Post date:** [April 22, 2020, 7:54pm UTC](https://community.sonarsource.com/t/java-duplicated-blocks-of-code-rule-for-native-methods/23507/1 "2020-04-22T19:54:11Z")

</div>

Sonar Cloud considers native Java methods as duplicated blocks but actually they aren’t.  
In our case, `native` methods have the same signature on the Java side but different implementations on the native side.

Please see the example by the following [link](https://sonarcloud.io/project/issues?id=exonum_exonum-java-binding&issues=AXF9hrv1RAqErMW6fXsN&open=AXF9hrv1RAqErMW6fXsN).

---

<div class="post-metadata">

**Author:** ![alban.auzeill](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alban.auzeill/32/36_2.png) [@alban.auzeill](https://community.sonarsource.com/u/alban.auzeill)\
**Post date:** [May 11, 2020, 4:18pm UTC](https://community.sonarsource.com/t/java-duplicated-blocks-of-code-rule-for-native-methods/23507/3 "2020-05-11T16:18:17Z")

</div>

Hi Oleg,

I agree, SonarCloud should not include native method declarations in its copy & paste detection. I created this ticket [SONARJAVA-3387](https://jira.sonarsource.com/browse/SONARJAVA-3387).

Thank for this valuable feedback,  
Alban

---

<div class="post-metadata">

**Author:** ![alban.auzeill](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alban.auzeill/32/36_2.png) [@alban.auzeill](https://community.sonarsource.com/u/alban.auzeill)\
**Post date:** [May 11, 2020, 4:56pm UTC](https://community.sonarsource.com/t/java-duplicated-blocks-of-code-rule-for-native-methods/23507/6 "2020-05-11T16:56:24Z")

</div>

Hi Oleg,

Because we may not fix this problem in a near future, as a workaround, you should configure `sonar.cpd.exclusions` to exclude files containing native methods.
