codeclimate/sonar-wrapper

View on GitHub
src/main/java/cc/Config.java

Summary

Maintainability
A
0 mins
Test Coverage

Rename field "config"
Open

    private Map<String, Object> config = new LinkedHashMap<>();
Severity: Major
Found in src/main/java/cc/Config.java by sonar-java

It's confusing to have a class member with the same name (case differences aside) as its enclosing class. This is particularly so when you consider the common practice of naming a class instance for the class itself.

Best practice dictates that any field or member with the same name as the enclosing class be renamed to be more descriptive of the particular aspect of the class it represents or holds.

Noncompliant Code Example

public class Foo {
  private String foo;

  public String getFoo() { }
}

Foo foo = new Foo();
foo.getFoo() // what does this return?

Compliant Solution

public class Foo {
  private String name;

  public String getName() { }
}

//...

Foo foo = new Foo();
foo.getName()

Exceptions

When the type of the field is the containing class and that field is static, no issue is raised to allow singletons named like the type.

public class Foo {
  ...
  private static Foo foo;
  public Foo getInstance() {
    if(foo==null) {
      foo = new Foo();
    }
    return foo;
  }
  ...
}

Provide the parametrized type for this generic.
Open

        for (Map.Entry entry : config.entrySet()) {
Severity: Major
Found in src/main/java/cc/Config.java by sonar-java

Generic types shouldn't be used raw (without type parameters) in variable declarations or return values. Doing so bypasses generic type checking, and defers the catch of unsafe code to runtime.

Noncompliant Code Example

List myList; // Noncompliant
Set mySet; // Noncompliant

Compliant Solution

List<String> myList;
Set<? extends Number> mySet;

There are no issues that match your filters.

Category
Status