Skip to content

Commit

Permalink
Fix small corner-case in "SerialVersionUIDInSerializableClass" rule, …
Browse files Browse the repository at this point in the history
…when property was declared inside private object. (#7346)
  • Loading branch information
PStrelchenko committed Jun 9, 2024
1 parent 9158f32 commit a896408
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class SerialVersionUIDInSerializableClass(config: Config) : Rule(
if (parentDeclaration is KtClass) "class" else "object"
)
)
return if (property.isConstant() && isLongProperty(property) && property.isPrivate()) {
val isPropertyPrivate = declaration.isPrivate() || property.isPrivate()
return if (property.isConstant() && isLongProperty(property) && isPropertyPrivate) {
null
} else {
SerialVersionUIDFindings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ class SerialVersionUIDInSerializableClassSpec {
assertThat(subject.compileAndLint(code)).isEmpty()
}

@Test
fun `does not report constant in private companion object`() {
val code = """
import java.io.Serializable
class C : Serializable {
private companion object {
const val serialVersionUID: Long = 1
}
}
""".trimIndent()
assertThat(subject.compileAndLint(code)).isEmpty()
}

companion object {
private const val WRONG_SERIAL_VERSION_UID_MESSAGE =
"The property `serialVersionUID` signature is not correct. `serialVersionUID` should be " +
Expand Down

0 comments on commit a896408

Please sign in to comment.