Skip to content

Commit e295300

Browse files
SONARJAVA-5513 Update rule metadata (#5146)
Co-authored-by: romainbrenguier <[email protected]>
1 parent 5e97012 commit e295300

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2230.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Marking a non-public method <code>@Async</code> or <code>@Transactional</code> is misleading because Spring does not recognize non-public methods,
3-
and so makes no provision for their proper invocation. Nor does Spring make provision for the methods invoked by the method it called.</p>
4-
<p>Therefore marking a private method, for instance, @Transactional can only result in a runtime error or exception if the method is annotated as
5-
@Transactional.</p>
2+
<p>Marking a non-public method <code>@Async</code> or <code>@Transactional</code> is misleading because, up to version 5, Spring does not recognize
3+
non-public methods, and so makes no provision for their proper invocation. Nor does Spring make provision for the methods invoked by the method it
4+
called. Since Spring 6, protected and package-private methods can be handled, but the issue remains for private methods.</p>
5+
<p>Therefore, marking a private method, for instance, @Transactional gives a false sense of security, and can lead to incorrect assumptions and
6+
potential bugs.</p>
7+
<h2>Exceptions</h2>
8+
<p>The rule targets all non-public methods for project using Spring up to Spring 5, but only private methods for Spring 6 because Spring 6 takes into
9+
account all non-private methods.</p>
610
<h2>How to fix it</h2>
711
<p>Declare the method <code>public</code>. Note that this action alone does not resolve the issue of direct instance calls from within the same class
812
(see rule {rule:java:S6809}), but it is a required precondition to fix it.</p>
@@ -28,6 +32,8 @@ <h3>Documentation</h3>
2832
Framework API - Annotation Interface Async</a> </li>
2933
<li> <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html">Spring
3034
Framework API - Annotation Interface Transactional</a> </li>
35+
<li> <a
36+
href="https://docs.spring.io/spring-framework/reference/6.2.6/data-access/transaction/declarative/annotations.html#transaction-declarative-annotations-method-visibility">Method visibility and @Transactional in proxy mode</a> </li>
3137
</ul>
3238
<h3>Articles &amp; blog posts</h3>
3339
<ul>

sonarpedia.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"languages": [
44
"JAVA"
55
],
6-
"latest-update": "2025-05-12T09:01:22.180389864Z",
6+
"latest-update": "2025-05-12T09:39:02.591637166Z",
77
"options": {
88
"no-language-in-filenames": true,
99
"preserve-filenames": false

0 commit comments

Comments
 (0)