Skip to content

Commit 777ae04

Browse files
SONARJAVA-5254 Update RSPEC before 8.10 release (#5030)
1 parent b5eac20 commit 777ae04

6 files changed

Lines changed: 43 additions & 12 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ <h3>How does this work?</h3>
152152
<h4>RSA (Rivest-Shamir-Adleman) and DSA (Digital Signature Algorithm)</h4>
153153
<p>The security of these algorithms depends on the difficulty of attacks attempting to solve their underlying mathematical problem.</p>
154154
<p>In general, a minimum key size of <strong>2048</strong> bits is recommended for both. It provides 112 bits of security. A key length of
155-
<strong>3072</strong> or <strong>4092</strong> should be preferred when possible.</p>
155+
<strong>3072</strong> or <strong>4096</strong> should be preferred when possible.</p>
156156
<h4>AES (Advanced Encryption Standard)</h4>
157157
<p>AES supports three key sizes: 128 bits, 192 bits and 256 bits. The security of the AES algorithm is based on the computational complexity of trying
158158
all possible keys.<br> A larger key size increases the number of possible keys and makes exhaustive search attacks computationally infeasible.

sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S5332.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"status": "ready",
1111
"tags": [
12-
"cwe"
12+
"cwe",
13+
"android"
1314
],
1415
"defaultSeverity": "Critical",
1516
"ruleSpecification": "RSPEC-5332",

sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S6293.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"constantCost": "5min"
1414
},
1515
"tags": [
16-
"cwe"
16+
"cwe",
17+
"android"
1718
],
1819
"defaultSeverity": "Major",
1920
"ruleSpecification": "RSPEC-6293",

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<h2>Why is this an issue?</h2>
2-
<p>A method annotated with Spring’s <code>@Async</code> or <code>@Transactional</code> annotations will not work as expected if invoked directly from
3-
within its class.</p>
4-
<p>This is because Spring generates a proxy class with wrapper code to manage the method’s asynchronicity (<code>@Async</code>) or to handle the
5-
transaction (<code>@Transactional</code>). However, when called using <code>this</code>, the proxy instance is bypassed, and the method is invoked
6-
directly without the required wrapper code.</p>
2+
<p>A method annotated with Spring’s <code>@Async</code>, <code>@Cacheable</code> or <code>@Transactional</code> annotations will not work as expected
3+
if invoked directly from within its class.</p>
4+
<p>This is because Spring generates a proxy class with wrapper code to manage the method’s asynchronicity (<code>@Async</code>), to cache methods
5+
invocations (<code>@Cacheable</code>), or to handle the transaction (<code>@Transactional</code>). However, when called using <code>this</code>, the
6+
proxy instance is bypassed, and the method is invoked directly without the required wrapper code.</p>
77
<h2>How to fix it</h2>
8-
<p>Replace calls to <code>@Async</code> or <code>@Transactional</code> methods via <code>this</code> with calls on an instance that was injected by
9-
Spring (<code>@Autowired</code>, <code>@Resource</code> or <code>@Inject</code>). The injected instance is a proxy on which the methods can be invoked
10-
safely.</p>
8+
<p>Replace calls to <code>@Async</code>, <code>@Cacheable</code> or <code>@Transactional</code> methods via <code>this</code> with calls on an
9+
instance that was injected by Spring (<code>@Autowired</code>, <code>@Resource</code> or <code>@Inject</code>). The injected instance is a proxy on
10+
which the methods can be invoked safely.</p>
1111
<h3>Code examples</h3>
1212
<h4>Noncompliant code example</h4>
1313
<pre data-diff-id="1" data-diff-type="noncompliant">
@@ -17,12 +17,19 @@ <h4>Noncompliant code example</h4>
1717
@Override
1818
public void process(Notification notification) {
1919
processAsync(notification); // Noncompliant, call bypasses proxy
20+
retrieveNotification(notification.id); // Noncompliant, call bypasses proxy and will not be cached
2021
}
2122

2223
@Async
2324
public processAsync(Notification notification) {
2425
// ...
2526
}
27+
28+
@Cacheable
29+
public Notification retrieveNotification(Long id) {
30+
// ...
31+
}
32+
2633
}
2734
</pre>
2835
<h4>Compliant solution</h4>
@@ -36,12 +43,18 @@ <h4>Compliant solution</h4>
3643
@Override
3744
public void process(Notification notification) {
3845
asyncNotificationProcessor.processAsync(notification); // Compliant, call via injected proxy
46+
asyncNotificationProcessor.retrieveNotification(notification.id); // Compliant, the call will be cached
3947
}
4048

4149
@Async
4250
public processAsync(Notification notification) {
4351
// ...
4452
}
53+
54+
@Cacheable
55+
public Notification retrieveNotification(Long id) {
56+
// ...
57+
}
4558
}
4659
</pre>
4760
<h2>Resources</h2>
@@ -51,12 +64,16 @@ <h3>Documentation</h3>
5164
Framework API - Annotation Interface Async</a> </li>
5265
<li> <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html">Spring
5366
Framework API - Annotation Interface Transactional</a> </li>
67+
<li> <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/annotation/Cacheable.html">Spring Framework
68+
API - Annotation Interface Cacheable</a> </li>
5469
</ul>
5570
<h3>Articles &amp; blog posts</h3>
5671
<ul>
5772
<li> <a href="https://www.baeldung.com/spring-async">Baeldung - How To Do @Async in Spring</a> </li>
5873
<li> <a href="https://stackoverflow.com/questions/22561775/spring-async-ignored">Stack Overflow - Spring @Async ignored</a> </li>
5974
<li> <a href="https://stackoverflow.com/questions/4396284/does-spring-transactional-attribute-work-on-a-private-method">Stack Overflow - Does Spring
6075
@Transactional attribute work on a private method?</a> </li>
76+
<li> <a href="https://docs.spring.io/spring-framework/reference/integration/cache/annotations.html#cache-annotations-cacheable">Spring docs, The
77+
@Cacheable Annotation</a> </li>
6178
</ul>
6279

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ <h2>Why is this an issue?</h2>
55
module and are commonly used to define the routes for different HTTP operations in a RESTful API.</p>
66
<p>If a method has a path template containing a placeholder, like "/api/resource/{id}", and there’s no <code>@PathVariable</code> annotation on a
77
method parameter to capture the id path variable, Spring will disregard the id variable.</p>
8+
<p>This rule will raise an issue if a method has a path template with a placeholder, but no corresponding <code>@PathVariable</code>, or
9+
vice-versa.</p>
810
<h2>How to fix it</h2>
911
<h3>Code examples</h3>
1012
<h4>Noncompliant code example</h4>
@@ -13,13 +15,23 @@ <h4>Noncompliant code example</h4>
1315
public ResponseEntity&lt;String&gt; getResourceById(Long id) { // Noncompliant - The 'id' parameter will not be automatically populated with the path variable value
1416
return ResponseEntity.ok("Fetching resource with ID: " + id);
1517
}
18+
19+
@GetMapping("/api/asset/")
20+
public ResponseEntity&lt;String&gt; getAssetById(@PathVariable Long id) { // Noncompliant - The 'id' parameter does not have a corresponding placeholder
21+
return ResponseEntity.ok("Fetching asset with ID: " + id);
22+
}
1623
</pre>
1724
<h4>Compliant solution</h4>
1825
<pre data-diff-id="1" data-diff-type="compliant">
1926
@GetMapping("/api/resource/{id}")
2027
public ResponseEntity&lt;String&gt; getResourceById(@PathVariable Long id) { // Compliant
2128
return ResponseEntity.ok("Fetching resource with ID: " + id);
2229
}
30+
31+
@GetMapping("/api/asset/{id}")
32+
public ResponseEntity&lt;String&gt; getAssetById(@PathVariable Long id) {
33+
return ResponseEntity.ok("Fetching asset with ID: " + id);
34+
}
2335
</pre>
2436
<h2>Resources</h2>
2537
<h3>Documentation</h3>

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-01-09T10:42:54.029515Z",
6+
"latest-update": "2025-02-14T14:49:23.786310Z",
77
"options": {
88
"no-language-in-filenames": true,
99
"preserve-filenames": false

0 commit comments

Comments
 (0)