SonarLint plugin on Intellij (IntelliJ IDEA 2024.1.1 (Ultimate Edition)) shows warnings like: Make "[field name]" transient or serializable
. I cannot get rid of it, even though I definitely should.
Here are the details. I have ParentDTO class (SpringBoot annotations here):
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.io.Serializable;
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "Description")
public class ParentDTO implements Serializable {
@NotNull
@Schema(description = "Test", requiredMode = Schema.RequiredMode.REQUIRED)
private String test;
@NotNull
@Schema(description = "Child", requiredMode = Schema.RequiredMode.REQUIRED)
private ChildDTO child;
}
and ChildDto class:
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "Child description")
public class ChildDTO {
@NotNull
@Schema(description = "Name", requiredMode = Schema.RequiredMode.REQUIRED)
private String name;
}
With that two classes I spoted Make "child" transient or serializable
warning on ParentDto class. Ok, my mistake, ChildDTO class should be also Serializable, so I changed to:
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.io.Serializable;
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "Child description")
public class ChildDTO implements Serializable {
@NotNull
@Schema(description = "Name", requiredMode = Schema.RequiredMode.REQUIRED)
private String name;
}
but suprisingly the warning has NOT gone. I tried to:
- Restart Intellij (with all caches cleared)
- Update SonarList plugin to the newest version
- Configure new project on Intellij on a brand new git clone
The warning is still there.
Then I did some stupid thing: I refactored ChildDTO class name to ChildDTOx class name – the warning has gone. What??? When I rolled back the warning appeared again. Next I added new class ChildDTODummy with the same structure as ChildDTO and added reference from ParentDTO:
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.io.Serializable;
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "Description")
public class ParentDTO implements Serializable {
@NotNull
@Schema(description = "Test", requiredMode = Schema.RequiredMode.REQUIRED)
private String test;
@NotNull
@Schema(description = "Child", requiredMode = Schema.RequiredMode.REQUIRED)
private ChildDTO child;
@NotNull
@Schema(description = "Child dummy", requiredMode = Schema.RequiredMode.REQUIRED)
private ChildDTODummy childDummy;
}
…and there is no warning like: Make "childDummy" transient or serializable
. I also removed implementation of Serializable interface from ChildDummy class and the additional warning still did not appear. What??? I think it should.
Does anybody has an idea what is going on here? Why SonarLint shows warning where it should not, and not showing where it should?
Thanks for any reply.