prasadtalasila/BITS-Darshini

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

Summary

Maintainability
B
4 hrs
Test Coverage

Rename "startByte" which hides the field declared at line 31.
Open

    int startByte = packetWrapper.getStartByte();

Overriding or shadowing a variable declared in an outer scope can strongly impact the readability, and therefore the maintainability, of a piece of code. Further, it could lead maintainers to introduce bugs because they think they're using one variable but are really using another.

Noncompliant Code Example

class Foo {
  public int myField;

  public void doSomething() {
    int myField = 0;
    ...
  }
}

See

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

  @Subscribe
  public void analyze(PacketWrapper packetWrapper) {
    if (Protocol.get("ICMP").equalsIgnoreCase(packetWrapper.getPacketType())) {
      setIcmpHeader(packetWrapper);
      String nextPacketType = setNextProtocolType();
src/main/java/in/ac/bits/protocolanalyzer/analyzer/link/EthernetAnalyzer.java on lines 77..94

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 154.

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 6 locations. Consider refactoring.
Open

  private void setIcmpHeader(PacketWrapper packetWrapper) {
    Packet packet = packetWrapper.getPacket();
    int startByte = packetWrapper.getStartByte();
    byte[] rawPacket = packet.getRawData();
    this.icmpHeader = Arrays.copyOfRange(rawPacket, startByte, startByte + IcmpHeader.TOTAL_HEADER_LENGTH);
src/main/java/in/ac/bits/protocolanalyzer/analyzer/link/EthernetAnalyzer.java on lines 43..48
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 47..52
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 45..50
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 44..49
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/UdpAnalyzer.java on lines 44..49

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 58.

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

Identical blocks of code found in 6 locations. Consider refactoring.
Open

  public void configure(EventBus eventBus, AnalysisRepository repository, String sessionName) {
    this.eventBus = eventBus;
    this.eventBus.register(this);
    this.repository = repository;
    this.indexName = "protocol_" + sessionName;
src/main/java/in/ac/bits/protocolanalyzer/analyzer/link/EthernetAnalyzer.java on lines 36..41
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 40..45
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 38..43
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 37..42
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/UdpAnalyzer.java on lines 37..42

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 50.

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 26 locations. Consider refactoring.
Open

  public short getCode(byte[] icmpHeader) {
    byte[] code = BitOperator.parse(icmpHeader, IcmpHeader.CODE_START_BIT, IcmpHeader.CODE_END_BIT);
    short returnVar = ByteOperator.parseBytesshort(code);
    return returnVar;
  }
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 66..70
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 72..76
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 78..82
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 89..93
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 95..99
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 101..105
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 107..111
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 64..68
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 70..74
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 76..80
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 82..86
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 93..97
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/IcmpAnalyzer.java on lines 63..67
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 63..67
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 69..73
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 75..79
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 81..85
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 87..91
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 93..97
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 99..103
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 105..109
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 116..120
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/UdpAnalyzer.java on lines 63..67
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/UdpAnalyzer.java on lines 69..73
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/UdpAnalyzer.java on lines 75..79

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 40.

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 26 locations. Consider refactoring.
Open

  public short getType_(byte[] icmpHeader) {
    byte[] type_ = BitOperator.parse(icmpHeader, IcmpHeader.TYPE__START_BIT, IcmpHeader.TYPE__END_BIT);
    short returnVar = ByteOperator.parseBytesshort(type_);
    return returnVar;
  }
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 66..70
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 72..76
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 78..82
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 89..93
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 95..99
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 101..105
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv4Analyzer.java on lines 107..111
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 64..68
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 70..74
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 76..80
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 82..86
src/main/java/in/ac/bits/protocolanalyzer/analyzer/network/IPv6Analyzer.java on lines 93..97
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/IcmpAnalyzer.java on lines 69..73
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 63..67
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 69..73
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 75..79
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 81..85
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 87..91
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 93..97
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 99..103
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 105..109
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/TcpAnalyzer.java on lines 116..120
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/UdpAnalyzer.java on lines 63..67
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/UdpAnalyzer.java on lines 69..73
src/main/java/in/ac/bits/protocolanalyzer/analyzer/transport/UdpAnalyzer.java on lines 75..79

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 40.

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

Local variable name 'type_' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
Open

    byte[] type_ = BitOperator.parse(icmpHeader, IcmpHeader.TYPE__START_BIT, IcmpHeader.TYPE__END_BIT);

Checks that local, non-final variable names conform to a specified pattern.A catch parameter is considered to be a local variable.

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 159).
Open

      IndexQuery query = builder.withIndexName(this.indexName).withType("icmp").withId(String.valueOf(packetWrapper.getPacketId())).withObject(entity).build();

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 103).
Open

    byte[] type_ = BitOperator.parse(icmpHeader, IcmpHeader.TYPE__START_BIT, IcmpHeader.TYPE__END_BIT);

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 107).
Open

    this.icmpHeader = Arrays.copyOfRange(rawPacket, startByte, startByte + IcmpHeader.TOTAL_HEADER_LENGTH);

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 121).
Open

    byte[] hdrchecksum = BitOperator.parse(icmpHeader, IcmpHeader.HDRCHECKSUM_START_BIT, IcmpHeader.HDRCHECKSUM_END_BIT);

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.

Consider simply returning the value vs storing it in local variable 'returnVar'
Open

    return returnVar;

UnnecessaryLocalBeforeReturn

Since: PMD 3.3

Priority: Medium

Categories: Style

Remediation Points: 50000

Avoid the creation of unnecessary local variables

Example:

public class Foo {
 public int foo() {
 int x = doSomething();
 return x; // instead, just 'return doSomething();'
 }
}

Consider simply returning the value vs storing it in local variable 'returnVar'
Open

    return returnVar;

UnnecessaryLocalBeforeReturn

Since: PMD 3.3

Priority: Medium

Categories: Style

Remediation Points: 50000

Avoid the creation of unnecessary local variables

Example:

public class Foo {
 public int foo() {
 int x = doSomething();
 return x; // instead, just 'return doSomething();'
 }
}

A switch with less than three branches is inefficient, use a if statement instead.
Open

    switch(nextHeaderType) {
      default: return Protocol.get("END_PROTOCOL");
    }

TooFewBranchesForASwitchStatement

Since: PMD 4.2

Priority: Medium

Categories: Style

Remediation Points: 50000

Switch statements are intended to be used to support complex branching behaviour. Using a switch for only a few cases is ill-advised, since switches are not as easy to understand as if-then statements. In these cases use the if-then statement to increase code readability.

Example:

// With a minimumNumberCaseForASwitch of 3
public class Foo {
 public void bar() {
 switch (condition) {
 case ONE:
 instruction;
 break;
 default:
 break; // not enough for a 'switch' stmt, a simple 'if' stmt would have been more appropriate
 }
 }
}

There are no issues that match your filters.

Category
Status