walkmod/walkmod-override-plugin

Wrong override for raw extension of super class

Closed this issue · 6 comments

Do not put an override on second compare method

private static abstract class XComparator implements Comparator {
        @Override
        public final int compare(Object o1, Object o2) {
            return compare((X) o1, (X) o2);
        }
        protected abstract int compare(X o1, X o2);
     }
rpau commented

Hi,

Thank you for reporting this issue. However, your example does not compile. Could you provide a clear example? The class XComparator has the template variable X in its definition?

Thanks

I will try to make a complete Example.

I took a look at the Override Visitor. Really not that difficult. A few "extract methods" won't hurt. ;-)

The parameter types checking loop looks fishy.
If you extend a parameterized class like Comparator as a raw type and have a method like compare
in your sub class that you define using specific types (the X in my example) that method may come as "valid" out of the loop because there are no type information in a raw usage.
But that is NOT always an override because one is a raw and the other is overloaded.
All IMHO without testing.

Do not generate @OverRide here.
I don't really understand why but Java 7 does not like it.

package de;

import java.util.Hashtable;

final class ThreadLocalMap extends ThreadLocal {

  public
  final
  Object childValue(Object parentValue) {
    Hashtable ht = (Hashtable) parentValue;
    if(ht != null) {
      return ht.clone();
    } else {
      return null;
    }
  }
}

rpau commented

You are right that the checking of the parameter types is a little fishy and the scenario you describe produce an error. I create an issue for this