prasadtalasila/BITS-Darshini

View on GitHub
src/main/java/in/ac/bits/protocolanalyzer/protocol/Protocol.java

Summary

Maintainability
A
0 mins
Test Coverage

Make the enclosing method "static" or remove this set.
Open

        classTable = new HashMap<String, CustomAnalyzer>();

Correctly updating a static field from a non-static method is tricky to get right and could easily lead to bugs if there are multiple class instances and/or multiple threads in play. Ideally, static fields are only updated from synchronized static methods.

This rule raises an issue each time a static field is updated from a non-static method.

Noncompliant Code Example

public class MyClass {

  private static int count = 0;

  public void doSomething() {
    //...
    count++;  // Noncompliant
  }
}

Make the enclosing method "static" or remove this set.
Open

        cellTable = new HashMap<String, Integer>();

Correctly updating a static field from a non-static method is tricky to get right and could easily lead to bugs if there are multiple class instances and/or multiple threads in play. Ideally, static fields are only updated from synchronized static methods.

This rule raises an issue each time a static field is updated from a non-static method.

Noncompliant Code Example

public class MyClass {

  private static int count = 0;

  public void doSomething() {
    //...
    count++;  // Noncompliant
  }
}

Make the enclosing method "static" or remove this set.
Open

        protocolTable = new HashMap<String, String>();

Correctly updating a static field from a non-static method is tricky to get right and could easily lead to bugs if there are multiple class instances and/or multiple threads in play. Ideally, static fields are only updated from synchronized static methods.

This rule raises an issue each time a static field is updated from a non-static method.

Noncompliant Code Example

public class MyClass {

  private static int count = 0;

  public void doSomething() {
    //...
    count++;  // Noncompliant
  }
}

Define a constant instead of duplicating this literal "ETHERNET" 4 times.
Open

        protocolTable.put("ETHERNET", "ETHERNET");

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.

Summary javadoc is missing.
Open

/**

Checks thatJavadoc summary sentence does not contain phrases that are not recommended to use.Summaries that contain only the {@inheritDoc} tag are skipped. Check alsoviolate Javadoc that does not contain first sentence.

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 'in.ac.bits.protocolanalyzer.analyzer.transport.TcpAnalyzer' import. Should be before 'org.springframework.web.context.WebApplicationContext'.
Open

import in.ac.bits.protocolanalyzer.analyzer.transport.TcpAnalyzer;

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 'in.ac.bits.protocolanalyzer.analyzer.CustomAnalyzer' import. Should be before 'org.springframework.web.context.WebApplicationContext'.
Open

import in.ac.bits.protocolanalyzer.analyzer.CustomAnalyzer;

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.

Extra separation in import group before 'org.springframework.beans.factory.annotation.Autowired'
Open

import org.springframework.beans.factory.annotation.Autowired;

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.

Extra separation in import group before 'lombok.extern.log4j.Log4j'
Open

import lombok.extern.log4j.Log4j;

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.

Extra separation in import group before 'in.ac.bits.protocolanalyzer.analyzer.CustomAnalyzer'
Open

import in.ac.bits.protocolanalyzer.analyzer.CustomAnalyzer;

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 'in.ac.bits.protocolanalyzer.analyzer.network.IPv4Analyzer' import. Should be before 'org.springframework.web.context.WebApplicationContext'.
Open

import in.ac.bits.protocolanalyzer.analyzer.network.IPv4Analyzer;

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 'in.ac.bits.protocolanalyzer.analyzer.link.EthernetAnalyzer' import. Should be before 'org.springframework.web.context.WebApplicationContext'.
Open

import in.ac.bits.protocolanalyzer.analyzer.link.EthernetAnalyzer;

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.

When doing a String.toLowerCase()/toUpperCase() call, use a Locale
Open

        return classTable.get(protocolName.toUpperCase());

UseLocaleWithCaseConversions

Since: PMD 2.0

Priority: Medium

Categories: Style

Remediation Points: 50000

When doing String.toLowerCase()/toUpperCase() conversions, use Locales to avoids problems with languages that have unusual conventions, i.e. Turkish.

Example:

class Foo {
 // BAD
 if (x.toLowerCase().equals('list')) { }

 /*
 * This will not match 'LIST' when in Turkish locale
 * The above could be
 * if (x.toLowerCase(Locale.US).equals('list')) { }
 * or simply
 * if (x.equalsIgnoreCase('list')) { }
 */
 // GOOD
 String z = a.toLowerCase(Locale.EN);
}

Avoid reassigning parameters such as 'protocolName'
Open

    public void addCustomAnalyzer(CustomAnalyzer analyzer, String protocolName,

AvoidReassigningParameters

Since: PMD 1.0

Priority: Medium High

Categories: Style

Remediation Points: 50000

Reassigning values to incoming parameters is not recommended. Use temporary local variables instead.

Example:

public class Foo {
 private void foo(String bar) {
 bar = 'something else';
 }
}

When doing a String.toLowerCase()/toUpperCase() call, use a Locale
Open

        cellTable.put(protocolName.toUpperCase(), cellStage);

UseLocaleWithCaseConversions

Since: PMD 2.0

Priority: Medium

Categories: Style

Remediation Points: 50000

When doing String.toLowerCase()/toUpperCase() conversions, use Locales to avoids problems with languages that have unusual conventions, i.e. Turkish.

Example:

class Foo {
 // BAD
 if (x.toLowerCase().equals('list')) { }

 /*
 * This will not match 'LIST' when in Turkish locale
 * The above could be
 * if (x.toLowerCase(Locale.US).equals('list')) { }
 * or simply
 * if (x.equalsIgnoreCase('list')) { }
 */
 // GOOD
 String z = a.toLowerCase(Locale.EN);
}

When doing a String.toLowerCase()/toUpperCase() call, use a Locale
Open

        protocolName = protocolName.toUpperCase();

UseLocaleWithCaseConversions

Since: PMD 2.0

Priority: Medium

Categories: Style

Remediation Points: 50000

When doing String.toLowerCase()/toUpperCase() conversions, use Locales to avoids problems with languages that have unusual conventions, i.e. Turkish.

Example:

class Foo {
 // BAD
 if (x.toLowerCase().equals('list')) { }

 /*
 * This will not match 'LIST' when in Turkish locale
 * The above could be
 * if (x.toLowerCase(Locale.US).equals('list')) { }
 * or simply
 * if (x.equalsIgnoreCase('list')) { }
 */
 // GOOD
 String z = a.toLowerCase(Locale.EN);
}

When doing a String.toLowerCase()/toUpperCase() call, use a Locale
Open

        return cellTable.get(protocolName.toUpperCase());

UseLocaleWithCaseConversions

Since: PMD 2.0

Priority: Medium

Categories: Style

Remediation Points: 50000

When doing String.toLowerCase()/toUpperCase() conversions, use Locales to avoids problems with languages that have unusual conventions, i.e. Turkish.

Example:

class Foo {
 // BAD
 if (x.toLowerCase().equals('list')) { }

 /*
 * This will not match 'LIST' when in Turkish locale
 * The above could be
 * if (x.toLowerCase(Locale.US).equals('list')) { }
 * or simply
 * if (x.equalsIgnoreCase('list')) { }
 */
 // GOOD
 String z = a.toLowerCase(Locale.EN);
}

There are no issues that match your filters.

Category
Status