OS: Windows 10, Ubuntu
SonarLint SonarSource 6.7.0.45926
Connected to SonarQube Enterprise Edition Version 7.9.4 (build 35981)
s1948 rule: Fields in a “Serializable” class should either be transient or serializable
SonarLint appears to be incorrectly detecting this rule as broken in a specific scenario:
class CustomSerializable implements Serializable {}
class AnotherCustomerSerializable implements Serializable {
private CustomSerializable customSerializable;
}
SonarLint will flag the object of type CustomSerializable in the AnotherCustomerSerializable class for breaking s1948, suggesting that it should either be transient or Serializable. In this scenario, CustomSerializable implements the Serializable interface already and so is-a Serializable, which should negate the need to instantiate customSerializable explicitly as type Serializable.
The Java docs indicate that “A Java object is serializable if its class or any of its superclasses implements either the java.io.Serializable interface or its subinterface, java.io.Externalizable” (available here) which seems to indicate that above warning for s1948 in this case is incorrect - am I misinterpreting the rule here?