Checker CallSuper   as of Julia version 2.6.0 (built on 6 Sep 2018)

belongs to group Basic

Identify possibly missing calls to super()


Java allows methods to call their implementation in the superclass, through the super.m(pars) syntax. It is sometimes the case that redefinitions are expected to call their implementation in the superclass. This checker identifies situations where a call to super.m(pars) seems to have been forgotten.

Action: Check if a call to super.m(pars) has been forgotten and add it consequently.

Examples


Consider the following classes:

public class TestSuper implements Cloneable {
  private final long time = System.currentTimeMillis();

  public void m() {}

  public long getTime() {
    return time;
  }

  @Override
  protected Object clone() {
    return this;
  }
}
public class A extends TestSuper {

  @Override
  public void m() {
    super.m();
  }
}
public class B extends TestSuper {

  @Override
  public void m() {
    super.m();
  }
}
public class C extends TestSuper {

  @Override
  public void m() {
    super.m();
  }
}
public class D extends TestSuper {

  @Override
  public void m() {
  }
}

This checker issues the following warning:

D.java:5: [CallSuper: CallSuperWarning] Should you probably call super.m here? 3 redefinitions call super and only 1 does not
TestSuper.java:12: [CallSuper: CallSuperWarning] Should you probably call super.clone here?

since method m() of class D does not call super.m(), differently from the other two redefinitions of m() in classes A, B and C. Moreover, method clone() should normally call super.clone(), but this does not happen at line 12 of class TestSuper.