From a39e170b23bd487352b613d58fe856f7c388d235 Mon Sep 17 00:00:00 2001
From: Johann Beleites
Date: Mon, 4 Mar 2024 17:56:32 +0100
Subject: [PATCH] SONARJAVA-4814 Improved S1948 RSPEC to better explain why
public collections are a problem (#4698)
---
.../resources/org/sonar/l10n/java/rules/java/S1948.html | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1948.html b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1948.html
index b372f22c88e..9dc9caa5127 100644
--- a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1948.html
+++ b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1948.html
@@ -9,10 +9,11 @@ Why is this an issue?
not exhibit unexpected behaviour when an instance is serialized.
This rule raises an issue on:
- - non-
Serializable
fields,
- - collection fields when they are not
private
(because they could be assigned non-Serializable
values externally),
-
- - when a field is assigned a non-
Serializable
type within the class.
+ - Non-
Serializable
fields.
+ - When a field is assigned a non-
Serializable
type within the class.
+ - Collection fields when they are not
private
. Values that are not serializable could be added to these collections externally. Due
+ to type erasure, it cannot be guaranteed that the collection will only contain serializable objects at runtime despite being declared as a
+ collection of serializable types.
How to fix it
Consider the following scenario.