Skip to content

Commit

Permalink
Issue #12210: Add method to ignore unstable checker framework violations
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyom-Yadav authored and romani committed Sep 19, 2022
1 parent e0f745a commit 701bd65
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 31 deletions.
7 changes: 6 additions & 1 deletion .ci/StarterRuleSet-AllRulesByCategory.groovy.txt
Expand Up @@ -120,7 +120,12 @@ ruleset {
EmptyMethodInAbstractClass
FinalClassWithProtectedMember
ImplementationAsType
Instanceof

// Using instanceof in equals method is alright
Instanceof {
ignoreTypeNames = 'CheckerFrameworkError'
}

LocaleSetDefault
NestedForLoop
PrivateFieldCouldBeFinal
Expand Down
Expand Up @@ -11,7 +11,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/Main.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-10288 or any of its aliases.</message>
Expand Down Expand Up @@ -77,7 +78,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20912 or any of its aliases.</message>
Expand All @@ -88,7 +90,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20915 or any of its aliases.</message>
Expand All @@ -99,7 +102,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20917 or any of its aliases.</message>
Expand All @@ -110,7 +114,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20918 or any of its aliases.</message>
Expand All @@ -121,7 +126,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20923 or any of its aliases.</message>
Expand All @@ -132,7 +138,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/ant/CheckstyleAntTask.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20926 or any of its aliases.</message>
Expand Down Expand Up @@ -176,7 +183,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/meta/XmlMetaReader.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-23288 or any of its aliases.</message>
Expand All @@ -198,7 +206,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/DescendantIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20533 or any of its aliases.</message>
Expand All @@ -209,7 +218,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/DescendantIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20534 or any of its aliases.</message>
Expand All @@ -220,7 +230,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/DescendantIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20536 or any of its aliases.</message>
Expand All @@ -231,7 +242,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/FollowingIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20414 or any of its aliases.</message>
Expand All @@ -242,7 +254,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/FollowingIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20415 or any of its aliases.</message>
Expand All @@ -253,7 +266,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/FollowingIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20418 or any of its aliases.</message>
Expand All @@ -264,7 +278,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/FollowingIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-20420 or any of its aliases.</message>
Expand All @@ -275,7 +290,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/PrecedingIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-10345 or any of its aliases.</message>
Expand All @@ -286,7 +302,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/PrecedingIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-10346 or any of its aliases.</message>
Expand All @@ -297,7 +314,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/PrecedingIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-10349 or any of its aliases.</message>
Expand All @@ -309,7 +327,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/PrecedingIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-10351 or any of its aliases.</message>
Expand All @@ -320,7 +339,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/ReverseDescendantIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-22037 or any of its aliases.</message>
Expand All @@ -331,7 +351,8 @@
</details>
</checkerFrameworkError>

<checkerFrameworkError unstable="false">
<!-- Error is considered unstable as temp-var changes with each run. -->
<checkerFrameworkError unstable="true">
<fileName>checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/xpath/iterators/ReverseDescendantIterator.java</fileName>
<specifier>required.method.not.called</specifier>
<message>@MustCall method close may not have been invoked on temp-var-22043 or any of its aliases.</message>
Expand Down
78 changes: 69 additions & 9 deletions .ci/checker-framework.groovy
@@ -1,4 +1,3 @@
import groovy.transform.EqualsAndHashCode
import groovy.transform.Field
import groovy.transform.Immutable
import groovy.util.slurpersupport.GPathResult
Expand Down Expand Up @@ -382,7 +381,6 @@ private static Set<CheckerFrameworkError> setDifference(final Set<CheckerFramewo
/**
* A class to represent the XML {@code checkerFrameworkError} node.
*/
@EqualsAndHashCode(excludes = ["lineNumber", "unstable"])
@Immutable
class CheckerFrameworkError implements Comparable<CheckerFrameworkError> {

Expand All @@ -398,6 +396,17 @@ class CheckerFrameworkError implements Comparable<CheckerFrameworkError> {
List<String> details
String lineContent
int lineNumber

/**
* Whether the error is unstable. Unstable errors in suppression list are not flagged as
* unnecessary suppressions.
*
* <p>An error is considered to be unstable when error message changes with each run.
* Some error messages contains strings like {@code temp-var-1234}, the numerical part changes
* with each run so the error is considered unstable. In such cases numerical values in
* {@code details} and {@code message} are replaced with empty string while comparing and
* hashing errors.
*/
boolean unstable

@Override
Expand Down Expand Up @@ -435,17 +444,68 @@ class CheckerFrameworkError implements Comparable<CheckerFrameworkError> {
return i
}

i = getMessage() <=> other.getMessage()
if (i != 0) {
return i
if (this.isUnstable() || other.isUnstable()) {
final String messageWithoutLineNumber = getMessage().replaceAll('\\d+', '')
final String thatMessageWithoutLineNumber = other.getMessage().replaceAll('\\d+', '')
i = messageWithoutLineNumber <=> thatMessageWithoutLineNumber
if (i != 0) {
return i
}

final List<String> detailsWithoutLineNumber = this.getDetails()*.replaceAll('\\d+', '')
final List<String> thatDetailsWithoutLineNumber =
other.getDetails()*.replaceAll('\\d+', '')

i = detailsWithoutLineNumber.join('') <=> thatDetailsWithoutLineNumber.join('')
if (i != 0) {
return i
}
}
else {
i = getMessage() <=> other.getMessage()
if (i != 0) {
return i
}

i = getLineContent() <=> other.getLineContent()
if (i != 0) {
return i
i = getDetails().join('') <=> other.getDetails().join('')
if (i != 0) {
return i
}
}

return getLineContent() <=> other.getLineContent()
}

@Override
boolean equals(Object object) {
if (this.is(object)) {
return true
}
if (!(object instanceof CheckerFrameworkError)) {
return false
}

return this.getDetails().join('') <=> other.getDetails().join('')
CheckerFrameworkError that = (CheckerFrameworkError) object

return (this <=> that) == 0
}

@Override
int hashCode() {
int result
if (unstable) {
result = (message != null ? message.replaceAll('\\d+', '').hashCode() : 0)
result = 31 * result + (details != null ? details*.replaceAll(
'\\d+', '').hashCode() : 0)
}
else {
result = (message != null ? message.hashCode() : 0)
result = 31 * result + (details != null ? details.hashCode() : 0)
}
result = 31 * result + (fileName != null ? fileName.hashCode() : 0)
result = 31 * result + (specifier != null ? specifier.hashCode() : 0)
result = 31 * result + (lineContent != null ? lineContent.hashCode() : 0)
return result
}

/**
Expand Down

0 comments on commit 701bd65

Please sign in to comment.