Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Sonar S2129 Constructors should not be used to instantiate "String", "BigInteger", "BigDecimal" and primitive-wrapper classes #1066

Open
jlerbsc opened this issue Jun 25, 2023 · 2 comments

Comments

@jlerbsc
Copy link
Contributor

jlerbsc commented Jun 25, 2023

While analyzing your project using our Automatic bug fixing software, i noticed that sonar rule S2129 was sometimes violated. If you wish, I can offer you a correction in the form of a PR.

https://sonarcloud.io/organizations/default/rules?open=java%3AS2129&q=S2129
"Calling constructors for String, BigInteger, BigDecimal and the objects used to wrap primitives is less efficient and less clear than relying on autoboxing or valueOf.
Consider simplifying when possible for more efficient and cleaner code."

Below are examples of the changes made by our software to correct this rule.

diff --git a/biojava-alignment/src/main/java/org/biojava/nbio/alignment/io/StockholmStructure.java b/biojava-alignment/src/main/java/org/biojava/nbio/alignment/io /StockholmStructure.java
index 97261433b..22783b43c 100644
--- a/biojava-alignment/src/main/java/org/biojava/nbio/alignment/io/StockholmStructure.java
+++ b/biojava-alignment/src/main/java/org/biojava/nbio/alignment/io/StockholmStructure.java
@@ -256.9 +256.8 @@ public class StockholmStructure {
                     }
                     String[] seqDetails = splitSeqName(sequencename);
                     seq.setDescription(seqDetails[0]);
- seq.setBioBegin((seqDetails[1] == null || seqDetails[1].trim().equals("") ? null: new Integer(
- seqDetails[1])));
- seq.setBioEnd((seqDetails[2] == null || seqDetails[2].trim().equals("") ? null: new Integer(seqDetails[2])));
+ seq.setBioBegin((seqDetails[1] == null || seqDetails[1].trim().equals("") ? null : Integer.valueOf(seqDetails[1])));
+ seq.setBioEnd((seqDetails[2] == null || seqDetails[2].trim().equals("") ? null: Integer.valueOf(seqDetails[2])));

                     seqs.add(seq);
             }
@josemduarte
Copy link
Contributor

That seems reasonable to me, thanks. Happy to review a PR.

jlerbsc added a commit to jlerbsc/biojava that referenced this issue Jun 27, 2023
…'BigInteger', 'BigDecimal' and primitive-wrapper classes (Issue biojava#1066)
@jlerbsc
Copy link
Contributor Author

jlerbsc commented Jun 27, 2023

The corresponding PR is #1067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants