prasadtalasila/BITS-Darshini

View on GitHub
src/main/java/in/ac/bits/protocolanalyzer/analyzer/AnalyzerCell.java

Summary

Maintainability
A
25 mins
Test Coverage

Method run has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    @Override
    public void run() {
        while (isRunning) {
            if (!isProcessing) {
                if (!inputQueue.isEmpty()) {
Severity: Minor
Found in src/main/java/in/ac/bits/protocolanalyzer/analyzer/AnalyzerCell.java - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Merge this if statement with the enclosing one.
Open

                if (!inputQueue.isEmpty()) {

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if (file != null) {
  if (file.isFile() || file.isDirectory()) {
    /* ... */
  }
}

Compliant Solution

if (file != null && isFileOrDirectory(file)) {
  /* ... */
}

private static boolean isFileOrDirectory(File file) {
  return file.isFile() || file.isDirectory();
}

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
Open

        } catch (InterruptedException e) {

InterruptedExceptions should never be ignored in the code, and simply logging the exception counts in this case as "ignoring". The throwing of the InterruptedException clears the interrupted state of the Thread, so if the exception is not handled properly the fact that the thread was interrupted will be lost. Instead, InterruptedExceptions should either be rethrown - immediately or after cleaning up the method's state - or the thread should be re-interrupted by calling Thread.interrupt() even if this is supposed to be a single-threaded application. Any other course of action risks delaying thread shutdown and loses the information that the thread was interrupted - probably without finishing its task.

Similarly, the ThreadDeath exception should also be propagated. According to its JavaDoc:

If ThreadDeath is caught by a method, it is important that it be rethrown so that the thread actually dies.

Noncompliant Code Example

public void run () {
  try {
    while (true) {
      // do stuff
    }
  }catch (InterruptedException e) { // Noncompliant; logging is not enough
    LOGGER.log(Level.WARN, "Interrupted!", e);
  }
}

Compliant Solution

public void run () {
  try {
    while (true) {
      // do stuff
    }
  }catch (InterruptedException e) {
    LOGGER.log(Level.WARN, "Interrupted!", e);
    // Restore interrupted state...
    Thread.currentThread().interrupt();
  }
}

See

At-clause should have a non-empty description.
Open

     * @param event

At-clause should have a non-empty description.
Open

     * @param protocol

Unused @param tag for 'sessionId'.
Open

     * @param sessionId

Checks the Javadoc of a method or constructor.

Violates parameters and type parametersfor which no param tags arepresent can be suppressed by defining propertyallowMissingParamTags.

Violates methods which return non-void but for which no return tag ispresent can be suppressed by defining propertyallowMissingReturnTag.

Violates exceptions which are declared to be thrown (by throws in the methodsignature or by throw new in the method body), but for which no throws tag ispresent by activation of property validateThrows.Note that throw new is not checked in the following places:

  • Inside a try block (with catch). It is not possible to determine if the thrownexception can be caught by the catch block as there is no knowledge of theinheritance hierarchy, so the try block is ignored entirely. However, catchand finally blocks, as well as try blocks without catch, are still checked.
  • Local classes, anonymous classes and lambda expressions. It is not known when thethrow statements inside such classes are going to be evaluated, so they are ignored.

ATTENTION: Checkstyle does not have information about hierarchy of exception typesso usage of base class is considered as separate exception type.As workaround you need to specify both types in javadoc (parent and exact type).

Javadoc is not required on a method that is tagged with the@Override annotation. However underJava 5 it is not possible to mark a method required for aninterface (this was corrected under Java 6). HenceCheckstyle supports using the convention of using a single{@inheritDoc} tag instead of all theother tags.

Note that only inheritable items will allow the{@inheritDoc} tag to be used in placeof comments. Static methods at all visibilities, private non-staticmethods and constructors are not inheritable.

For example, if the following method isimplementing a method required by an interface, then theJavadoc could be done as:

<source><br>/** {@inheritDoc} */<br>public int checkReturnTag(final int aTagIndex,<br> JavadocTag[] aTags,<br> int aLineNo)<br> </source>

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

At-clause should have a non-empty description.
Open

     * @param analyzer

First sentence of Javadoc is missing an ending period.
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.

First sentence of Javadoc is missing an ending period.
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 'lombok.extern.log4j.Log4j' import. Should be before 'org.springframework.stereotype.Component'.
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.

Wrong lexicographical order for 'lombok.Setter' import. Should be before 'org.springframework.stereotype.Component'.
Open

import lombok.Setter;

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.

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.

At-clause should have a non-empty description.
Open

     * @param analyzer

At-clause should have a non-empty description.
Open

     * @param destinationCell

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

import in.ac.bits.protocolanalyzer.analyzer.event.EndAnalysisEvent;

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.event.PacketTypeDetectionEvent' import. Should be before 'org.springframework.stereotype.Component'.
Open

import in.ac.bits.protocolanalyzer.analyzer.event.PacketTypeDetectionEvent;

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.

At-clause should have a non-empty description.
Open

     * @param sessionId

Wrong lexicographical order for 'com.google.common.eventbus.Subscribe' import. Should be before 'org.springframework.stereotype.Component'.
Open

import com.google.common.eventbus.Subscribe;

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.

Wrong lexicographical order for 'com.google.common.eventbus.EventBus' import. Should be before 'org.springframework.stereotype.Component'.
Open

import com.google.common.eventbus.EventBus;

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.

At-clause should have a non-empty description.
Open

     * @param cellID

Wrong lexicographical order for 'lombok.Getter' import. Should be before 'org.springframework.stereotype.Component'.
Open

import lombok.Getter;

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.

At-clause should have a non-empty description.
Open

     * @param packet

Extra separation in import group before 'com.google.common.eventbus.EventBus'
Open

import com.google.common.eventbus.EventBus;

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.event.EndAnalysisEvent' import. Should be before 'org.springframework.stereotype.Component'.
Open

import in.ac.bits.protocolanalyzer.analyzer.event.EndAnalysisEvent;

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.persistence.repository.AnalysisRepository' import. Should be before 'org.springframework.stereotype.Component'.
Open

import in.ac.bits.protocolanalyzer.persistence.repository.AnalysisRepository;

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.

First sentence of Javadoc is missing an ending period.
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.

These nested if statements could be combined
Open

                if (!inputQueue.isEmpty()) {
                    isProcessing = true;
                    process(inputQueue.poll());
                }

CollapsibleIfStatements

Since: PMD 3.1

Priority: Medium

Categories: Style

Remediation Points: 50000

Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.

Example:

void bar() {
 if (x) { // original implementation
 if (y) {
 // do stuff
 }
 }
}

void bar() {
 if (x && y) { // optimized implementation
 // do stuff
 }
}

There are no issues that match your filters.

Category
Status