Skip to content

Commit

Permalink
Makes HasQualifierParameter an inherited type; Fixes #3831 (#3832)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-rasmud authored Oct 28, 2020
1 parent b6a3b37 commit 363f182
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 13 deletions.
4 changes: 0 additions & 4 deletions checker/tests/tainting/ExtendHasQual.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ static class Super {
@HasQualifierParameter(Tainted.class)
static class Buffer extends Super {}

// :: error: (missing.has.qual.param)
static class MyBuffer1 extends Buffer {}

@HasQualifierParameter(Tainted.class)
Expand All @@ -28,18 +27,15 @@ static class MyBuffer4 extends Buffer {}
@HasQualifierParameter(Tainted.class)
interface BufferInterface {}

// :: error: (missing.has.qual.param)
static class ImplementsBufferInterface1 implements BufferInterface {}

@HasQualifierParameter(Tainted.class)
static class ImplementsBufferInterface2 implements BufferInterface {}

// :: error: (missing.has.qual.param)
static class Both1 extends Buffer implements BufferInterface {}

@HasQualifierParameter(Tainted.class)
static class Both2 extends Buffer implements BufferInterface {}

// :: error: (missing.has.qual.param)
static class Both3 extends Super implements BufferInterface {}
}
31 changes: 31 additions & 0 deletions checker/tests/tainting/InheritQualifierParameter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.checkerframework.checker.tainting.qual.Tainted;
import org.checkerframework.checker.tainting.qual.Untainted;
import org.checkerframework.framework.qual.HasQualifierParameter;
import org.checkerframework.framework.qual.NoQualifierParameter;

@HasQualifierParameter(Tainted.class)
public class InheritQualifierParameter {}

class SubHasQualifierParameter extends InheritQualifierParameter {
void test(@Untainted SubHasQualifierParameter arg) {
// :: error: (assignment.type.incompatible)
@Tainted SubHasQualifierParameter local = arg;
}
}

@NoQualifierParameter(Tainted.class)
// :: error: (conflicting.qual.param)
class SubHasQualifierParameter1 extends InheritQualifierParameter {}

@NoQualifierParameter(Tainted.class)
class InheritNoQualifierParameter {}

class SubNoQualifierParameter extends InheritNoQualifierParameter {
void test(@Untainted SubNoQualifierParameter arg) {
@Tainted SubNoQualifierParameter local = arg;
}
}

@HasQualifierParameter(Tainted.class)
// :: error: (conflicting.qual.param)
@Tainted class SubNoQualifierParameter1 extends InheritNoQualifierParameter {}
18 changes: 18 additions & 0 deletions checker/tests/tainting/InnerHasQualifierParameter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import org.checkerframework.checker.tainting.qual.Tainted;
import org.checkerframework.framework.qual.HasQualifierParameter;

@HasQualifierParameter(Tainted.class)
public class InnerHasQualifierParameter {

@HasQualifierParameter(Tainted.class)
interface TestInterface {
public void testMethod();
}

public void test() {
TestInterface test =
new TestInterface() {
public void testMethod() {}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class TestNoQualifierParameterConflicting {
static class Super {}

@NoQualifierParameter(Tainted.class)
// :: error: (missing.has.qual.param)
// :: error: (conflicting.qual.param)
static class Sup extends Super {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
Expand Down Expand Up @@ -54,15 +55,16 @@
* {@code @Untainted} MyStringBuffer
* </pre>
*
* <p>This annotation may not be written on the same class as {@code NoQualifierParameter} for the
* same hierarchy.
* <p>When a class is {@code @HasQualifierParameter}, all its subclasses are as well.
*
* <p>When {@code @HasQualifierParameter} is written on a package, it is equivalent to writing it on
* each class in that package with the same arguments, including classes in sub-packages. It can be
* disabled on a specific class by writing {@code @NoQualifierParameter} on that class.
* <p>When {@code @HasQualifierParameter} is written on a package, it is equivalent to writing that
* annotation on each class in the package or in a sub-package. It can be disabled on a specific
* class and its subclasses by writing {@code @NoQualifierParameter} on that class. This annotation
* may not be written on the same class as {@code NoQualifierParameter} for the same hierarchy.
*
* @see NoQualifierParameter
*/
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.PACKAGE})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This is a declaration annotation that applies to type declarations. Some classes conceptually
* take a type qualifier parameter. This annotations indicates that this class explicitly does not
* do so. If {@code HasQualifierParameter} is enabled by default, for example, by writing {@code
* HasQualifierParameter} on a package, then this annotation can disable it for a specific class.
* take a type qualifier parameter. This annotation indicates that this class and its subclasses
* explicitly do not do so. The only reason to write this annotation is when {@code
* HasQualifierParameter} is enabled by default, by writing {@code HasQualifierParameter} on a
* package.
*
* <p>When a class is {@code @NoQualifierParameter}, all its subclasses are as well.
*
* <p>One or more top qualifiers must be given for the hierarchies for which there are no qualifier
* parameters. This annotation may not be written on the same class as {@code HasQualifierParameter}
* for the same hierarchy.
*
* <p>It is an error for a superclass to be {@code @HasQualifierParameter} but a subclass to be
* {@code @NoQualifierParameter} for the same hierarchy.
*
* @see HasQualifierParameter
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface NoQualifierParameter {

/**
Expand Down

0 comments on commit 363f182

Please sign in to comment.