JD.INF.AREC occurs when the method calls itself without any prior checks.

Vulnerability and risk

If this method is called, it will call itself again and again, and then the program stack will overflow and the JVM will throw a StackOverflowError. Obviously this is not what the programmer intended.

Mitigation and prevention

JD.INF.AREC has three possible causes.

  • There is a misspelled instance object. For example, instead of "super.equals(o)", the programmer typed "this.equals(o)" Fix the spelling of the instance object.
  • The argument of the method is not cast for a specific type. For example, it should be this.equals((MyType)o). Cast the argument to a specific type.
  • A condition for terminating the recursion is missing. Add a condition that will stop recursion.

Example 1

10    /**
11     * Implementation required by the interface.
12     * @param o - object to compare
13     * @return true, if equal.
14     */
15    public boolean equals(Object o) {
16      return this.equals(o);
17    }

JD.INF.AREC is reported for call on line 16: Apparent infinite recursion by calling 'equals(java.lang.Object)' from itself