← 输入框|github.com|刷新
Skip to content

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

Open

Description

@jlerbsc

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);
             }

Activity

  1. josemduarte commented on Jun 26, 2023

    @josemduarte
    Contributor

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

  2. jlerbsc commented on Jun 27, 2023

    @jlerbsc
    ContributorAuthor

    The corresponding PR is #1067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions