Java Developer Tools

Audit - Rules - Dead Code

Description
This group contains audit rules that look for code that is not being used or cannot be reached.

Rules:

Details

Constant Condition

Summary
A constant expression in a conditional statement indicates either dead or debugging code.

Description
Using a constant as a conditional expression could indicate either debugging code or dead code.

Security Implications
Both variants are a potential security risk and should be avoided.

Example
The following statement was inserted as a way to skip a block of business code below it and should be removed:

if (true) return null;

Invocation of Default Constructor

Summary
Default constructors should not be invoked within subclass constructors.

Description
This audit rule looks for invocations of the default constructor for a superclass within a constructor in the subclass. The invocation is unnecessary because the compiler will automatically add such a call.

Example
The following constructor invocation would be flagged as a violation:

    public Point(int x, int y) {
        super();
        ...;
    }

Unnecessary Catch Block

Summary
Catch blocks should do more than rethrow the exception.

Description
This audit rule looks for catch blocks whose body consists only of a throw of the exception that was just caught. Unless there is another catch block in the same try statement that catches a superclass of the exception's class, such catch blocks only serve to clutter the code.

Example
The following catch clause would be flagged as a violation:

    try {
        ...
    } catch (NullPointerException exception) {
        throw exception;
    }

Unnecessary Default Constructor

Summary
Default constructors should not be declared unless necessary.

Description
This audit rule looks for declarations of default (zero-argument) constructors in classes with no other constructors, whose body is either empty or contains only an invocation of the superclass' default constructor.

Example
The following constructor would be flagged as a violation:

    public UnnecessaryConstructor() {
        super();
    }

Unnecessary Override

Summary
Methods that override other methods should do more than invoke the overridden method.

Description
This audit rule looks for methods whose body consists only of an invocation of the overridden method with the same argument values. Such methods can safely be removed.

Example
The following method would be flagged as a violation because it only invokes the method it overrides:

    public void clear() {
        super.clear();
    }

Unused Field

Summary
Fields that are not used should be removed.

Description
This audit rule checks for any private instance fields that are not referenced within their declaring class.

Example
The following field would be flagged as a violation if it is not used within its declaring class:

    private int unused;

Unused Label

Summary
Labels that are not used should be removed.

Description
This audit rule checks for any labeled statements whose labels are not used in either a break or continue statement within the scope of the labeled statement.

Example
The following label would be flagged as a violation because it is not used within the body of the for loop:

    int sum = 0;
    sumElements: for (int i = 0; i < array.length; i++) {
        sum = sum + array[i];
    }

Unused Method

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.