You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A collection value may be of fixed size even though it has a mutable type. (Or, the value may be of fixed size in the scope in which it is analyzed, such as within a method call to which it is passed as an argument.)
For instance, a method might take a CharSequence and create an index into it by comparing it to CharSequence#length:
Currently, the Index Checker forbids this code. This is because CharSequences can be mutable, so the return type of CharSequence#length does not have an upper bound annotation. In this specific case, seq is immutable, so the type of seq.length() could be @IndexOrHigh("seq").
A proposal to remedy this is to add a @FixedSize or @Readonly annotation that can be applied to collections. So, the method above would be annotated:
On its own, this annotation does nothing. The annotation is trusted.
In CharSequence, we would then annotate the length method so that if the collection is @FixedSize, length returns @IndexOrHigh, using something like @EnsuresQualifierIf (although the actual syntax would likely have to be different):
This is distinct from #154 in that this issue refers to specific fixed-size instances of collections that are generally mutable. Issue #154 refers to classes that are always immutable.
…1716)
As a partial fix for kelloggm#154 and kelloggm#197, this skips warnings on uses of base classes of sequences which contain methods that change the length and have both mutable and immutable implementations.
In order to do that, `SourceChecker` had to be modified to allow overriding `shouldSkipUses`, so that we can ignore these classes in addition to classes matching the pattern specified by the user.
The base classes are:
- `java.util.List`
- `java.util.AbstractList`
Index jdk chages:
- add upper bound annotations to index parameters in `java.util.List` and `java.util.AbstractList`
A collection value may be of fixed size even though it has a mutable type. (Or, the value may be of fixed size in the scope in which it is analyzed, such as within a method call to which it is passed as an argument.)
For instance, a method might take a CharSequence and create an index into it by comparing it to
CharSequence#length
:Currently, the Index Checker forbids this code. This is because
CharSequence
s can be mutable, so the return type ofCharSequence#length
does not have an upper bound annotation. In this specific case,seq
is immutable, so the type ofseq.length()
could be@IndexOrHigh("seq")
.A proposal to remedy this is to add a
@FixedSize
or@Readonly
annotation that can be applied to collections. So, the method above would be annotated:On its own, this annotation does nothing. The annotation is trusted.
In
CharSequence
, we would then annotate thelength
method so that if the collection is@FixedSize
,length
returns@IndexOrHigh
, using something like@EnsuresQualifierIf
(although the actual syntax would likely have to be different):Then, we can implicitly add the
@FixedSize
annotation to known fixed-size implementations ofCharSequence
, such asString
.The text was updated successfully, but these errors were encountered: