You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2025/07/01 01:44:28 UTC
(lucene) branch main updated: eliminate more redundant errorprone checks (#14869)
This is an automated email from the ASF dual-hosted git repository.
rmuir pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new f5bdc1e0ca1 eliminate more redundant errorprone checks (#14869)
f5bdc1e0ca1 is described below
commit f5bdc1e0ca1184e7b5f4a0ad171253fa6735ed9d
Author: Robert Muir <rm...@apache.org>
AuthorDate: Mon Jun 30 21:44:21 2025 -0400
eliminate more redundant errorprone checks (#14869)
* EmptyBlockTag: ecj linter detects missing descriptions for all these.
* StringCharset: ast-grep rule
* SunApi: forbidden-apis takes care
* ThreeLetterTimeZoneID: ast-grep rule
---
.../groovy/lucene.validation.error-prone.gradle | 10 +++----
gradle/validation/ast-grep/rules/errorprone.yml | 32 ++++++++++++++++++++++
gradle/validation/ast-grep/tests/errorprone.yml | 19 +++++++++++++
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/build-tools/build-infra/src/main/groovy/lucene.validation.error-prone.gradle b/build-tools/build-infra/src/main/groovy/lucene.validation.error-prone.gradle
index e7e05d87258..63703c7fdd7 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.validation.error-prone.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.validation.error-prone.gradle
@@ -162,7 +162,7 @@ allprojects { prj ->
// '-Xep:CheckReturnValue:OFF', // we don't use these annotations
'-Xep:CollectionToArraySafeParameter:ERROR',
// '-Xep:ComparableType:OFF',
- // '-Xep:ComparingThisWithNull:ERROR', // we use ast-grep for this check
+ // '-Xep:ComparingThisWithNull:OFF', // we use ast-grep for this check
'-Xep:ComparisonOutOfRange:ERROR',
// '-Xep:CompatibleWithAnnotationMisuse:OFF', // we don't use this annotation
// '-Xep:CompileTimeConstant:OFF', // we don't use this annotation
@@ -395,7 +395,7 @@ allprojects { prj ->
// '-Xep:DoNotMockAutoValue:OFF', // we don't use autovalue
// '-Xep:DoubleCheckedLocking:OFF', // TODO: there are problems
'-Xep:DuplicateDateFormatField:WARN',
- '-Xep:EmptyBlockTag:WARN',
+ // '-Xep:EmptyBlockTag:OFF', // ECJ takes care
// '-Xep:EmptyCatch:OFF', // ECJ takes care
// '-Xep:EmptySetMultibindingContributions:OFF', // we don't use this annotation
// '-Xep:EnumOrdinal:OFF', // noisy
@@ -570,11 +570,11 @@ allprojects { prj ->
// '-Xep:StreamResourceLeak:OFF', // TODO: there are problems
'-Xep:StreamToIterable:WARN',
// '-Xep:StringCaseLocaleUsage:OFF', // noisy, can use forbidden-apis for this
- '-Xep:StringCharset:WARN',
+ // '-Xep:StringCharset:OFF', // we use ast-grep for this
'-Xep:StringFormatWithLiteral:WARN',
// '-Xep:StringSplitter:OFF', // noisy, can use forbidden-apis for this
'-Xep:SystemConsoleNull:WARN',
- '-Xep:SunApi:WARN',
+ // '-Xep:SunApi:OFF', // we use forbidden-apis for this
'-Xep:SuperCallToObjectMethod:WARN',
// '-Xep:SwigMemoryLeak:OFF', // we don't use swig
// '-Xep:SynchronizeOnNonFinalField:OFF', // noisy
@@ -582,7 +582,7 @@ allprojects { prj ->
// '-Xep:ThreadLocalUsage:OFF', // noisy
// '-Xep:ThreadPriorityCheck:OFF', // noisy, forbidden APIs can do this
// '-Xep:ThrowIfUncheckedKnownUnchecked:OFF', // we don't use these google libraries
- '-Xep:ThreeLetterTimeZoneID:WARN',
+ // '-Xep:ThreeLetterTimeZoneID:OFF', // we use ast-grep for this
'-Xep:TimeUnitConversionChecker:WARN',
// '-Xep:ToStringReturnsNull:OFF', // TODO: there are problems
// '-Xep:TruthAssertExpected:OFF', // we don't use truth
diff --git a/gradle/validation/ast-grep/rules/errorprone.yml b/gradle/validation/ast-grep/rules/errorprone.yml
index f099288f86e..e4a3db6eb2e 100644
--- a/gradle/validation/ast-grep/rules/errorprone.yml
+++ b/gradle/validation/ast-grep/rules/errorprone.yml
@@ -149,3 +149,35 @@ severity: error
message: |
`main` methods must be `public`, `static`, and `void`
url: https://errorprone.info/bugpattern/IncorrectMainMethod
+---
+# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
+id: ThreeLetterTimeZoneID
+language: java
+rule:
+ pattern: $$$.getTimeZone("$ZONE")
+severity: error
+constraints:
+ ZONE:
+ # three-letter zone
+ regex: "^[A-Z][A-Z][A-Z]$"
+ # exempt UTC/GMT
+ not:
+ regex: "(UTC|GMT)"
+message: Three-letter time zone identifiers are deprecated, may be ambiguous, and might not do what you intend
+note: The full IANA time zone ID should be used instead.
+url: https://errorprone.info/bugpattern/ThreeLetterTimeZoneID
+---
+# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/refs/heads/main/schemas/java_rule.json
+id: StringCharset
+language: java
+rule:
+ any:
+ - pattern: new String($ARG, "$CHARSET")
+ - pattern: $$$.getBytes("$CHARSET")
+constraints:
+ CHARSET:
+ # these are available in StandardCharsets
+ regex: "(US-ASCII|UTF-16|UTF-8)"
+severity: error
+message: Prefer StandardCharsets over using string names for charsets
+url: https://errorprone.info/bugpattern/StringCharset
diff --git a/gradle/validation/ast-grep/tests/errorprone.yml b/gradle/validation/ast-grep/tests/errorprone.yml
index 318317f19a9..cccd5a26f3e 100644
--- a/gradle/validation/ast-grep/tests/errorprone.yml
+++ b/gradle/validation/ast-grep/tests/errorprone.yml
@@ -103,3 +103,22 @@ invalid:
public void main() {}
- |
public static int main() {}
+---
+id: ThreeLetterTimeZoneID
+invalid:
+ - TimeZone.getTimeZone("EST")
+valid:
+ - TimeZone.getTimeZone("UTC")
+ - TimeZone.getTimeZone("America/New_York")
+---
+id: StringCharset
+invalid:
+ - |
+ new String(bytes, "UTF-8")
+ - |
+ "abc".getBytes("UTF-16LE")
+valid:
+ - |
+ new String(bytes, "GB2312")
+ - |
+ new String(bytes, StandardCharsets.UTF_8)