tomokinakamaru/silverchain

View on GitHub
src/test/java/parser/Tests.java

Summary

Maintainability
A
2 hrs
Test Coverage

Method bulkTestData has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  static Arguments[] bulkTestData() {
    return new Arguments[] {
      args(AgParser::qualifiedName, "foo"),
      args(AgParser::qualifiedName, "foo.bar"),
      args(AgParser::qualifiedName, "foo.bar.baz"),
Severity: Major
Found in src/test/java/parser/Tests.java - About 2 hrs to fix

    Define a constant instead of duplicating this literal "Foo {}" 3 times.
    Open

        test(AgParser::classDeclaration, "Foo {}");
    Severity: Critical
    Found in src/test/java/parser/Tests.java by sonar-java

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    public void run() {
      prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
      execute("action1");
      release("action1");
    }
    
    @SuppressWarning("all")                            // Compliant - annotations are excluded
    private void method1() { /* ... */ }
    @SuppressWarning("all")
    private void method2() { /* ... */ }
    
    public String method3(String a) {
      System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
      return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
    }
    

    Compliant Solution

    private static final String ACTION_1 = "action1";  // Compliant
    
    public void run() {
      prepare(ACTION_1);                               // Compliant
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define and throw a dedicated exception instead of using a generic one.
    Open

          throw new RuntimeException(e);
    Severity: Major
    Found in src/test/java/parser/Tests.java by sonar-java

    Using such generic exceptions as Error, RuntimeException, Throwable, and Exception prevents calling methods from handling true, system-generated exceptions differently than application-generated errors.

    Noncompliant Code Example

    public void foo(String bar) throws Throwable {  // Noncompliant
      throw new RuntimeException("My Message");     // Noncompliant
    }
    

    Compliant Solution

    public void foo(String bar) {
      throw new MyOwnRuntimeException("My Message");
    }
    

    Exceptions

    Generic exceptions in the signatures of overriding methods are ignored, because overriding method has to follow signature of the throw declaration in the superclass. The issue will be raised on superclass declaration of the method (or won't be raised at all if superclass is not part of the analysis).

    @Override
    public void myMethod() throws Exception {...}
    

    Generic exceptions are also ignored in the signatures of methods that make calls to methods that throw generic exceptions.

    public void myOtherMethod throws Exception {
      doTheThing();  // this method throws Exception
    }
    

    See

    Define a constant instead of duplicating this literal "foo()" 5 times.
    Open

          args(AgParser::method, "foo()"),
    Severity: Critical
    Found in src/test/java/parser/Tests.java by sonar-java

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    public void run() {
      prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
      execute("action1");
      release("action1");
    }
    
    @SuppressWarning("all")                            // Compliant - annotations are excluded
    private void method1() { /* ... */ }
    @SuppressWarning("all")
    private void method2() { /* ... */ }
    
    public String method3(String a) {
      System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
      return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
    }
    

    Compliant Solution

    private static final String ACTION_1 = "action1";  // Compliant
    
    public void run() {
      prepare(ACTION_1);                               // Compliant
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    There are no issues that match your filters.

    Category
    Status