I got Duplicated Lines which is actually it should not

I have two response data class and using moshi which both almost same and marks as duplicate, i think it shouldn’t marks as duplicate

@JsonClass(generateAdapter = false)
data class MovieTvCastItemResponse(

  @Json(name = "cast_id")
  val castId: Int? = null,

  @Json(name = "character")
  val character: String? = null,

  @Json(name = "gender")
  val gender: Int? = null,

  @Json(name = "credit_id")
  val creditId: String? = null,

  @Json(name = "known_for_department")
  val knownForDepartment: String? = null,

  @Json(name = "original_name")
  val originalName: String? = null,

  @Json(name = "popularity")
  val popularity: Double? = null,

  @Json(name = "name")
  val name: String? = null,

  @Json(name = "profile_path")
  val profilePath: String? = null,

  @Json(name = "id")
  val id: Int? = null,

  @Json(name = "adult")
  val adult: Boolean? = null,

  @Json(name = "order")
  val order: Int? = null
)
@JsonClass(generateAdapter = false)
data class MovieTvCrewItemResponse(

  @Json(name = "gender")
  val gender: Int? = null,

  @Json(name = "credit_id")
  val creditId: String? = null,

  @Json(name = "known_for_department")
  val knownForDepartment: String? = null,

  @Json(name = "original_name")
  val originalName: String? = null,

  @Json(name = "popularity")
  val popularity: Double? = null,

  @Json(name = "name")
  val name: String? = null,

  @Json(name = "profile_path")
  val profilePath: String? = null,

  @Json(name = "id")
  val id: Int? = null,

  @Json(name = "adult")
  val adult: Boolean? = null,

  @Json(name = "department")
  val department: String? = null,

  @Json(name = "job")
  val job: String? = null
)

Hi @waffiqaziz ,
This article is about how SonarQube defines executable lines of code
It discusses what is considered executable code and what is not. Executable lines are used to calculate missing test coverage. Each line of code containing a statement is usually considered executable, with some exceptions. Some examples of non-executable code are method signatures, package statements, and variable declarations.

In the context of your previous question about SonarQube reporting variable assignments as code duplication, this article explains why this happens. SonarQube’s scanning algorithm only considers the left-hand side of an assignment (the variable name) as executable code, not the right-hand side (the assigned value). This means that if you have multiple lines assigning values to the same variable, they will be considered duplicates even if the values are different.

You can exclude this file from duplacation check using the parameter sonar.cpd.exclusions.

Let me know if you have other questions!

1 Like

Hi @waffiqaziz,

From your example declarations of fields gender ... adult are duplicated in both classes. Depending on you design decisions this might or might not be extracted to a separate entity. If you think that this is not a duplication you can ignore the file for duplications via sonar.cpd.exclusions as @Bachri_Abdel suggested.

You can also shuffle the fields to workaround algorithm, however, that might not be a good solution for you.

Best,
Margarita

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.