-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotating classes of util package #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. I had some relatively minor comments.
pom.xml
Outdated
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a second copy of the maven-compiler-plugin
, which is the same problem we had with commons-lang earlier today.
@@ -38,7 +43,7 @@ | |||
* @throws MathIllegalArgumentException when indices exceeds range | |||
*/ | |||
@Override | |||
public int pivotIndex(final double[] work, final int begin, final int end) | |||
public int pivotIndex(final double[] work, final @LessThan("#3") @IndexFor("#1") int begin, final @Positive @LTEqLengthOf("#1") int end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the return type of this method be @IndexFor("#1")
?
@@ -317,7 +328,7 @@ public static int distanceInf(int[] p1, int[] p2) | |||
* @param strict Whether the order should be strict. | |||
* @return {@code true} if sorted, {@code false} otherwise. | |||
*/ | |||
public static <T extends Comparable<? super T>> boolean isMonotonic(T[] val, | |||
public static <T extends Comparable<? super T>> boolean isMonotonic(@PolyUpperBound @PolyLowerBound @PolySameLen T @MinLen(1) [] val, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should change these to @PolyAll
@@ -823,10 +838,11 @@ public int compare(PairDoubleInteger o1, | |||
* @param to Final index of the range to be copied, exclusive. (This index may lie outside the array.) | |||
* @return the copied array. | |||
*/ | |||
public static double[] copyOfRange(double[] source, int from, int to) { | |||
@SuppressWarnings("index:argument.type.incompatible") // #1: As FastMath.min(len, source.length - from)) is the minimum of both the arguments, the expression <= source.length - fron and <= output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the comment: "the expression <= source.length - fron and <= output" is very unclear - what does "the expression" refer to? There's also a typo: "fron" should be "from".
public MultidimensionalCounter(int ... size) throws NotStrictlyPositiveException { | ||
dimension = size.length; | ||
this.size = MathArrays.copyOf(size); | ||
@SuppressWarnings("index:assignment.type.incompatible") // #1: By #0.1, this.size.length = size.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not annotate/stub MathArrays.copyOf
to return @SameLen("#1")
?
@@ -223,6 +231,7 @@ public int getDimension() { | |||
* @throws OutOfRangeException if {@code index} is not between | |||
* {@code 0} and the value returned by {@link #getSize()} (excluded). | |||
*/ | |||
@SuppressWarnings("index:array.access.unsafe.high") // #1: i < last < dimension which is the length of indices and uniCounterOffset | |||
public int[] getCounts(int index) throws OutOfRangeException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely index
should have an annotation here. If nothing else, it should definitely be @NonNegative
to avoid the exception below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking better. Nice work.
@@ -174,7 +177,7 @@ public static boolean parseFixedstring(final String source, | |||
final int endIndex = startIndex + expected.length(); | |||
if ((startIndex >= source.length()) || | |||
(endIndex > source.length()) || | |||
(source.substring(startIndex, endIndex).compareTo(expected) != 0)) { | |||
(source.substring(startIndex, endIndex).compareTo(expected) != 0)) { // #1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect this call to substring
to not issue an error, because the expected type for both arguments is IndexOrHigh
- which should both be established by the conditionals, as your suppress warning comment notes. Can you write a test case like this code and submit a bug? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explanation @SuppressWarnings
was wrong, it actually shows array.access.unsafe.low
error as it cannot recognise pos.getIndex()
as @NonNegative
.
The PR with ParsePosition annotation is open, so I have provided a link in the comment.
@SuppressWarnings({"index:array.access.unsafe.low", "index:argument.type.incompatible"}) /* | ||
#1: node is always @NonNegative as it is changed only in #0.1 where it is minimum of 2*node + 1(or 2) and either pivotsHeap.length or end | ||
pivotsHeap.length is @NonNegative as it is a length, end is also @NonNegative as it is initialized 0 and changed only in #0.2 where end = pivot >= k that is @NonNegative | ||
#3: begin and end are @NonNegative as t is assign |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "as t is assign" mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only minor issues here, but the Travis build is failing, which you should look into.
@@ -83,11 +83,11 @@ public PivotingStrategyInterface getPivotingStrategy() { | |||
@SuppressWarnings({"index:array.access.unsafe.low", "index:argument.type.incompatible"}) /* | |||
#1: node is always @NonNegative as it is changed only in #0.1 where it is minimum of 2*node + 1(or 2) and either pivotsHeap.length or end | |||
pivotsHeap.length is @NonNegative as it is a length, end is also @NonNegative as it is initialized 0 and changed only in #0.2 where end = pivot >= k that is @NonNegative | |||
#3: begin and end are @NonNegative as t is assign | |||
#3: begin and end are @NonNegative as it is initialised with @NonNegative values in #0. and changed to only @NonNegative values in #0.2 and #0.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "#0." mean here? Are you referring to "#0.3"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, a minor nit on English grammar: "it" should only be used for a singular antecedent. In this case, the antecedent is "begin and end", which is plural; therefore, the appropriate pronoun is "they". The sentence should read: "begin and end are @NonNegative as they are initialised..."
@kelloggm It is ready for review again. |
pom.xml
Outdated
@@ -516,6 +530,47 @@ | |||
|
|||
<build> | |||
<plugins> | |||
<plugin> | |||
<!-- This plugin will set properties values using dependency information --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation in this file.
@SuppressWarnings("unchecked") | ||
public static <T> T[][] buildArray(final Field<T> field, final int rows, final int columns) { | ||
@SuppressWarnings({"unchecked","index:array.access.unsafe.high.range"}) // i < rows which is the number of rows in array | ||
public static <T> T[][] buildArray(final Field<T> field, final @NonNegative int rows, final @NonNegative int columns) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation says that columns
may be negative.
@SuppressWarnings({"index:array.access.unsafe.high","index:array.access.unsafe.low"}) /* | ||
#1: j >= 0 is checked and j < xLen as j is max n + 1 - xLen where n is max xLen + hLen - 2 | ||
k < hLen is checked | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the parameters should be @MinLen(1)
pom.xml
Outdated
<compilerArgs> | ||
<!-- location of the annotated JDK, which comes from a Maven dependency --> | ||
<arg>-Xbootclasspath/p:${annotatedJdk}</arg> | ||
<arg>-AonlyDefs=^org\.apache\.commons\.math4\.util\.</arg> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add -ArequirePrefixInWarningSuppressions
and -AwarnUnneededSuppressions
as in commons-lang?
int begin = 0; | ||
int end = work.length; | ||
@SuppressWarnings({"index:array.access.unsafe.low", "index:argument.type.incompatible"}) /* | ||
#1: node is always @NonNegative as it is changed only in #0.1 where it is minimum of 2*node + 1(or 2) and either pivotsHeap.length or end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then node should be annotated @NonNegative
. Possibly begin
and end
as well.
@panacekcz made the changes you suggested |
Annotated OpenIntToFieldHashMap.java and FastMathCalc.java
Annotated OpenIntToDoubleHashMap.java and FastMath.java
Pull requests merged: |
@kelloggm @panacekcz This is ready to be merged, if you approve all the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The annotations look good. See comments about missing reference. Other than that, I think this is ready to be merged.
@@ -566,6 +590,9 @@ public T value() | |||
* @exception ConcurrentModificationException if the map is modified during iteration | |||
* @exception NoSuchElementException if there is no element left in the map | |||
*/ | |||
@SuppressWarnings({"index:assignment.type.incompatible", "index:array.access.unsafe.low", "index:array.access.unsafe.high", "index:unary.increment.type.incompatible"}) /* | |||
#1: These statement is never executed with next = states.length because when next = states.length - 1, the try catch block makes next = -2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear what statement this refers to - I presume it is the ++next
expression.
@@ -267,6 +275,7 @@ public ResizableDoubleArray(int initialCapacity, double expansionFactor, double | |||
* @throws MathIllegalArgumentException if the parameters are not valid. | |||
* @throws NullArgumentException if expansionMode is null | |||
*/ | |||
@SuppressWarnings("index:assignment.type.incompatible") // internalArray is @MinLen(1) and startIndex is @IndexFor("internalArray"), hence 0 < 1 - 0 + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this refer to #1
?
@panacekcz updated with the review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kelloggm, do you want to review again? Otherwise I think it can be merged.
Annotated the classes MathArrays.java, MedianOf3PivotingStrategy.java and MultidimensionalCounter.java