nlpub/watset-java

View on GitHub
src/main/java/org/nlpub/watset/cli/Command.java

Summary

Maintainability
A
1 hr
Test Coverage

Define a constant instead of duplicating this literal "parameters are not initialized" 3 times.
Open

        this.parameters = requireNonNull(parameters, "parameters are not initialized");

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.

Replace this use of System.out or System.err by a logger.
Open

            return new BufferedWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8));

When logging a message there are several important requirements which must be fulfilled:

  • The user must be able to easily retrieve the logs
  • The format of all logged message must be uniform to allow the user to easily read the log
  • Logged data must actually be recorded
  • Sensitive data must only be logged securely

If a program directly writes to the standard outputs, there is absolutely no way to comply with those requirements. That's why defining and using a dedicated logger is highly recommended.

Noncompliant Code Example

System.out.println("My Message");  // Noncompliant

Compliant Solution

logger.log("My Message");

See

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    @SuppressWarnings("unused")
    public final static class LocalParameters {
        /**
         * The local clustering algorithm.
         */
Severity: Minor
Found in src/main/java/org/nlpub/watset/cli/Command.java and 1 other location - About 45 mins to fix
src/main/java/org/nlpub/watset/cli/Command.java on lines 108..121

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 54.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    @SuppressWarnings("unused")
    public final static class GlobalParameters {
        /**
         * The global clustering algorithm.
         */
Severity: Minor
Found in src/main/java/org/nlpub/watset/cli/Command.java and 1 other location - About 45 mins to fix
src/main/java/org/nlpub/watset/cli/Command.java on lines 90..103

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 54.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Extra separation in import group before 'java.util.Objects.isNull'
Open

import static java.util.Objects.isNull;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Line is longer than 100 characters (found 108).
Open

        @Parameter(required = true, description = "Global clustering algorithm", names = {"-g", "--global"})

Checks for long lines.

Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Line is longer than 100 characters (found 106).
Open

        @Parameter(required = true, description = "Local clustering algorithm", names = {"-l", "--local"})

Checks for long lines.

Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

'static' modifier out of order with the JLS suggestions.
Open

    public final static class FixedClustersParameters {

Checks that the order of modifiers conforms to the suggestions inthe JavaLanguage specification, § 8.1.1, 8.3.1, 8.4.3 and9.4. The correct order is:

  1. public
  2. protected
  3. private
  4. abstract
  5. default
  6. static
  7. final
  8. transient
  9. volatile
  10. synchronized
  11. native
  12. strictfp

In additional, modifiers are checked to ensure all annotations aredeclared before all other modifiers.

Rationale: Code is easier to read if everybody follows a standard.

ATTENTION: We skiptype annotations from validation.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Using the '.*' form of import should be avoided - java.io.*.
Open

import java.io.*;

Checks that there are no import statements that use the * notation.

Rationale: Importing all classes from a package or staticmembers from a class leads to tight coupling between packagesor classes and might lead to problems when a new version of alibrary introduces name clashes.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Member name 'k' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
Open

        public Integer k;

Wrong lexicographical order for 'java.util.HashMap' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import java.util.HashMap;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.nio.charset.StandardCharsets' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import java.nio.charset.StandardCharsets;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Line is longer than 100 characters (found 115).
Open

        @DynamicParameter(description = "Local clustering algorithm parameters", names = {"-lp", "--local-params"})

Checks for long lines.

Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Line is longer than 100 characters (found 117).
Open

        @DynamicParameter(description = "Global clustering algorithm parameters", names = {"-gp", "--global-params"})

Checks for long lines.

Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.util.Map' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import java.util.Map;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.util.stream.Stream' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import java.util.stream.Stream;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Line is longer than 100 characters (found 108).
Open

        @Parameter(names = {"-s", "--seed"}, description = "Random seed", converter = RandomConverter.class)

Checks for long lines.

Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.nio.file.Files' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import java.nio.file.Files;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

'static' modifier out of order with the JLS suggestions.
Open

    public final static class GlobalParameters {

Checks that the order of modifiers conforms to the suggestions inthe JavaLanguage specification, § 8.1.1, 8.3.1, 8.4.3 and9.4. The correct order is:

  1. public
  2. protected
  3. private
  4. abstract
  5. default
  6. static
  7. final
  8. transient
  9. volatile
  10. synchronized
  11. native
  12. strictfp

In additional, modifiers are checked to ensure all annotations aredeclared before all other modifiers.

Rationale: Code is easier to read if everybody follows a standard.

ATTENTION: We skiptype annotations from validation.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

<p> tag should be preceded with an empty line.</p>
Open

     * <p>

Checks the Javadoc paragraph.

Checks that:

  • There is one blank line between each of two paragraphs.
  • Each paragraph but the first has <p> immediately before the first word, withno space after.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.io.*' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import java.io.*;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.util.Objects.isNull' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import static java.util.Objects.isNull;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

'static' modifier out of order with the JLS suggestions.
Open

    public final static class MainParameters {

Checks that the order of modifiers conforms to the suggestions inthe JavaLanguage specification, § 8.1.1, 8.3.1, 8.4.3 and9.4. The correct order is:

  1. public
  2. protected
  3. private
  4. abstract
  5. default
  6. static
  7. final
  8. transient
  9. volatile
  10. synchronized
  11. native
  12. strictfp

In additional, modifiers are checked to ensure all annotations aredeclared before all other modifiers.

Rationale: Code is easier to read if everybody follows a standard.

ATTENTION: We skiptype annotations from validation.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

<p> tag should be placed immediately before the first word, with no space after.</p>
Open

     * <p>

Checks the Javadoc paragraph.

Checks that:

  • There is one blank line between each of two paragraphs.
  • Each paragraph but the first has <p> immediately before the first word, withno space after.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Line is longer than 100 characters (found 104).
Open

            return new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)).lines();

Checks for long lines.

Rationale: Long lines are hard to read in printouts or if developershave limited screen space for the source code, e.g. if the IDEdisplays additional information like project tree, class hierarchy,etc.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.lang.System.Logger.Level' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import java.lang.System.Logger.Level;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.nio.file.Path' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import java.nio.file.Path;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Wrong lexicographical order for 'java.util.Objects.requireNonNull' import. Should be before 'org.nlpub.watset.util.ABCFormat'.
Open

import static java.util.Objects.requireNonNull;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

'static' modifier out of order with the JLS suggestions.
Open

    public final static class LocalParameters {

Checks that the order of modifiers conforms to the suggestions inthe JavaLanguage specification, § 8.1.1, 8.3.1, 8.4.3 and9.4. The correct order is:

  1. public
  2. protected
  3. private
  4. abstract
  5. default
  6. static
  7. final
  8. transient
  9. volatile
  10. synchronized
  11. native
  12. strictfp

In additional, modifiers are checked to ensure all annotations aredeclared before all other modifiers.

Rationale: Code is easier to read if everybody follows a standard.

ATTENTION: We skiptype annotations from validation.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Extra separation in import group before 'java.io.*'
Open

import java.io.*;

Checks that the groups of import declarations appear in the order specifiedby the user. If there is an import but its group is not specified in theconfiguration such an import should be placed at the end of the import list.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

There are no issues that match your filters.

Category
Status