typetools / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
1.02k stars 355 forks source link

Inheritance of classes with a qualifier parameter #3400

Open smillst opened 4 years ago

smillst commented 4 years ago

If a class extends a @HasQualifierParameter class (or implements a @HasQualifierParameter interface), then that class must also be marked @HasQualifierParameter. A particular subclass should be able to specify which qualifier parameter should be used for the super class. (This is similar to class StringList implements List<String> {...}.) For example,

 @HasQualifierParameter(Tainted.class)
 class Buffer {
     void append(@PolyTainted Buffer this, @PolyTainted String s) { ... }
 }
 @HasQualifierParameter(Tainted.class)
 @Tainted class TaintedBuffer extends @Tainted Buffer {
     @Override
     void append(@Tainted TaintedBuffer this, @Tainted String s) { ... } // legal override
 }

@Untainted TaintedBuffer is an invalid type.

See test case in checker/tests/tainting/SubClassHasQP.java and manual section in generics.tex.

t-rasmud commented 4 years ago

3832 makes @HasQualifierParameter an inherited type annotation addressing the requirement: "If a class extends a @HasQualifierParameter class (or implements a @HasQualifierParameter interface), then that class must also be marked

@HasQualifierParameter. " The requirement "A particular subclass should be able to specify which qualifier parameter should be used for the super class." remains to be addressed.