diff --git a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1905.html b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1905.html index 5a345f543b4..2349efbe34e 100644 --- a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1905.html +++ b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S1905.html @@ -12,6 +12,23 @@
As a result, it’s generally advised to avoid unnecessary casting expressions. Instead, rely on the language’s type system to ensure type safety and code clarity.
Casts from int to float, from long to float, and from long to double
+can document potential precision loss. Although Java performs these widening conversions implicitly, they can lose precision. This rule preserves
+casts that document awareness of potential precision loss, as required by {rule:java:S9395}. The cast does not prevent rounding or preserve the
+original value’s precision.
Compile-time constants between -224 and 224 (inclusive) for float, and between -253 and
+253 (inclusive) for double, do not lose precision during conversion. Redundant casts of these constants are still
+reported.
+class NumericConversions {
+ void convert(int intValue, long longValue) {
+ float first = (float) intValue; // Compliant
+ float second = (float) longValue; // Compliant
+ double third = (double) longValue; // Compliant
+ float constant = (float) 1; // Noncompliant
+ }
+}
+
Casting may be required to distinguish the method to call in the case of overloading:
class A {}
@@ -62,4 +79,8 @@ Documentation
@Transactional(readOnly = true) - Read-only transactions do not perform write operations, so there is no risk of committing partial
or inconsistent data.save, update, delete,
+ persist, merge, flush or insert). In that case, the method has not modified any data when the
+ exception occurs, so there is nothing to roll back.Explicitly specify rollbackFor to include the checked exceptions that should trigger a rollback. This is the most common fix, as most
diff --git a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9395.html b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9395.html
index b562ada93dc..c41ef99df92 100644
--- a/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9395.html
+++ b/sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S9395.html
@@ -38,9 +38,9 @@
Simply adding a cast may hide a bug, which is why no automatic fix is proposed.
-For integer arithmetic expressions such as a / b converted to a floating-point type, casting the result would not fix the
-integer division or overflow. Instead, one of the operands should be cast before the operation, as described by rule {rule:java:S2184}. Such
-expressions are not reported by this rule when {rule:java:S2184} already reports them.
For integer arithmetic expressions such as a / b converted to a floating-point type, casting the result would not fix the integer
+division or overflow. Instead, one of the operands should be cast before the operation, as described by rule {rule:java:S2184}. Such expressions are
+not reported by this rule when {rule:java:S2184} already reports them.
diff --git a/sonarpedia.json b/sonarpedia.json
index 60076c6b738..51c21601bd8 100644
--- a/sonarpedia.json
+++ b/sonarpedia.json
@@ -4,7 +4,7 @@
"JAVA"
],
"profiles-path": "./sonar-java-plugin/src/main/resources/profiles",
- "latest-update": "2026-10-22T11:55:36.615101096Z",
+ "latest-update": "2026-10-29T13:05:53.900556946Z",
"options": {
"no-language-in-filenames": true,
"preserve-filenames": false