# Code Duplication not detected

**URL:** <https://community.sonarsource.com/t/code-duplication-not-detected/51785>\
**Category:** SonarQube Server / Community Build\
**Tags:** python, duplications, scanner\
**Created:** [October 20, 2021, 12:55pm UTC](https://community.sonarsource.com/t/code-duplication-not-detected/51785 "2021-10-20T12:55:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dreamer](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@Dreamer](https://community.sonarsource.com/u/Dreamer)\
**Post date:** [October 20, 2021, 12:55pm UTC](https://community.sonarsource.com/t/code-duplication-not-detected/51785/1 "2021-10-20T12:55:00Z")

</div>

Template for a good bug report, formatted with [Markdown](https://commonmark.org/help/):

- SonarQube Version used: 8.9 LTS Enterprise Edition. Scanner Version used: 4.6.2.2472

I have an example where I observe a strange behaviour on code duplications:  
Assume, this is the content of a Python file:

```auto
class ClassA():
    config_dict = {}
    source_type = None

    def doSomething(self, config_dict, source_type):
        try:
            self.logger.warning("doNothing")

        except WorkflowException as err:
            self.logger.warning("Any warning message to print {} and {}".format(source_type, err.message))
            if Constants.MY_CONSTANT:
                self.logger.error("Error Message")
                UtilityClass.cleanup(config_dict[ConfigurationDict.TARGET_DIR], config_dict[ConfigurationDict.BUILD_PLATFORM])
                ReportClass.write_json_file(self.config_parser, self.traceability_report, None)
                sys.exit(1)
            else:
                self.logger.warning(
                    "Warning message: {}"
                    .format(source_type))
                if source_type == ConfigurationDict.C:
                    self.config_parser.is_c_executable = False
                if source_type == ConfigurationDict.CPP:
                    self.config_parser.is_cpp_executable = False

class ClassB():
    config_dict = {}
    source_type = None

    def doSomething(self, config_dict, source_type):
        try:
            self.logger.warning("doNothing")

        except WorkflowException as err:
            self.logger.warning("Any warning message to print {} and {}".format(source_type, err.message))
            if Constants.MY_CONSTANT:
                self.logger.error("Error Message")
                UtilityClass.cleanup(config_dict[ConfigurationDict.TARGET_DIR], config_dict[ConfigurationDict.BUILD_PLATFORM])
                ReportClass.write_json_file(self.config_parser, self.traceability_report, None)
                sys.exit(1)
            else:
                self.logger.warning(
                    "Warning message: {}"
                    .format(source_type))
                if source_type == ConfigurationDict.C:
                    self.config_parser.is_c_executable = False
                if source_type == ConfigurationDict.CPP:
                    self.config_parser.is_cpp_executable = False
        finally:
            WorkflowAnalysisUtil.retry_count = 0

```

As you can see, there are two different classes, but having the same function with almost the same content (for ClassB, there is an additional finally block which does not exist in ClassA).  
When running analysis using scanner, for sure, this code duplication will be detected.

But when changing line `self.logger.warning("Any warning message to print {} and {}".format(source_type, err.message))` to `self.logger.warning("Foo {} and {}".format(source_type, err.message))` in function `doSomething()` of **ClassA** , the code duplication is not reported anymore!

Note: Also applying

```auto
sonar.cpd.python.minimumtokens=1
sonar.cpd.python.minimumLines=1
sonar.cpd.cross_project=true

```

in properties file does not have any effect!

Any help is welcome!

Thank you in advance!
