2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2023-06-01 14:30:56 +02:00
|
|
|
Appending `String.valueOf()` to a `String` decreases the code readability.
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-01 14:30:56 +02:00
|
|
|
The argument passed to `String.valueOf()` should be directly appended instead.
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-09 16:36:32 +02:00
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
2023-06-01 14:30:56 +02:00
|
|
|
String message = "Output is " + String.valueOf(12);
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-09 16:36:32 +02:00
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
2023-06-01 14:30:56 +02:00
|
|
|
String message = "Output is " + 12;
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
2021-04-28 18:08:03 +02:00
|
|
|
|
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
Directly append the argument of String.valueOf().
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== on 16 Aug 2013, 12:51:37 Dinesh Bolkensteyn wrote:
|
|
|
|
\[~ann.campbell.2] I though you didn't like 'source code' ... but here it is "and decreases the readability of the source code" ;-)
|
|
|
|
|
|
|
|
=== on 16 Aug 2013, 14:30:04 Dinesh Bolkensteyn wrote:
|
|
|
|
The deprecatied rule covered also this case AFAIK:
|
|
|
|
|
|
|
|
|
|
|
|
----
|
|
|
|
String a = String.valueOf("foo");
|
|
|
|
----
|
|
|
|
|
|
|
|
which will not be covered by this rule.
|
|
|
|
|
|
|
|
=== on 16 Aug 2013, 15:20:24 Dinesh Bolkensteyn wrote:
|
|
|
|
Implemented by \http://jira.codehaus.org/browse/SONARJAVA-241
|
|
|
|
|
|
|
|
=== on 17 Aug 2013, 15:54:50 Ann Campbell wrote:
|
|
|
|
I don't [~dinesh.bolkensteyn]], but without a list of rules, I try to conform to what appears to be the established standard. :-)
|
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|