Browse Source

Upgrade Checkstyle to 9.3 (#83314)

Checkstyle 9.3 has been released, and contains a fix for the memory
problems we saw in previous versions. Upgrade to this version.

Note that the IDEA config has also been updated, but the plugin
doesn't yet have 9.3 as an option according to the release notes.
This shouldn't be a problem.
Rory Hunter 3 years ago
parent
commit
2282cf75d0

+ 1 - 1
.idea/checkstyle-idea.xml

@@ -4,7 +4,7 @@
     <option name="configuration">
       <map>
         <entry key="active-configuration" value="PROJECT_RELATIVE:$PROJECT_DIR$/checkstyle_ide.xml:Elasticsearch" />
-        <entry key="checkstyle-version" value="8.42" />
+        <entry key="checkstyle-version" value="9.2" />
         <entry key="copy-libs" value="false" />
         <entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
         <entry key="location-1" value="BUNDLED:(bundled):Google Checks" />

+ 1 - 1
build-conventions/build.gradle

@@ -65,7 +65,7 @@ dependencies {
     api 'org.apache.maven:maven-model:3.6.2'
     api 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0'
     api 'org.apache.rat:apache-rat:0.11'
-    compileOnly "com.puppycrawl.tools:checkstyle:8.45.1"
+    compileOnly "com.puppycrawl.tools:checkstyle:9.3"
     api('com.diffplug.spotless:spotless-plugin-gradle:6.0.0') {
       exclude module: "groovy-xml"
     }

+ 3 - 3
build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/HiddenFieldCheck.java

@@ -2,17 +2,17 @@
  * @notice
  * checkstyle: Checks Java source code for adherence to a set of rules.
  * Copyright (C) 2001-2021 the original author or authors.
-
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
-
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
-
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

+ 7 - 11
build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java

@@ -121,6 +121,8 @@ public class MissingJavadocTypeCheck extends AbstractCheck {
         return CommonUtil.EMPTY_INT_ARRAY;
     }
 
+    // suppress deprecation until https://github.com/checkstyle/checkstyle/issues/11166
+    @SuppressWarnings("deprecation")
     @Override
     public void visitToken(DetailAST ast) {
         if (shouldCheck(ast)) {
@@ -140,14 +142,7 @@ public class MissingJavadocTypeCheck extends AbstractCheck {
      * @return whether we should check a given node.
      */
     private boolean shouldCheck(final DetailAST ast) {
-        final Scope customScope;
-
-        if (ScopeUtil.isInInterfaceOrAnnotationBlock(ast)) {
-            customScope = Scope.PUBLIC;
-        } else {
-            final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
-            customScope = ScopeUtil.getScopeFromMods(mods);
-        }
+        final Scope customScope = ScopeUtil.getScope(ast);
         final Scope surroundingScope = ScopeUtil.getSurroundingScope(ast);
 
         final String outerTypeName = ast.findFirstToken(TokenTypes.IDENT).getText();
@@ -155,9 +150,10 @@ public class MissingJavadocTypeCheck extends AbstractCheck {
         return customScope.isIn(scope)
             && (surroundingScope == null || surroundingScope.isIn(scope))
             && (excludeScope == null
-                || customScope.isIn(excludeScope) == false
-                || surroundingScope != null && surroundingScope.isIn(excludeScope) == false)
-            && AnnotationUtil.containsAnnotation(ast, skipAnnotations) == false
+                || !customScope.isIn(excludeScope)
+                || surroundingScope != null
+                && !surroundingScope.isIn(excludeScope))
+            && !AnnotationUtil.containsAnnotation(ast, skipAnnotations)
             && ignorePattern.matcher(outerTypeName).find() == false;
     }
 

+ 1 - 1
build-tools-internal/version.properties

@@ -4,7 +4,7 @@ lucene            = 9.0.0
 bundled_jdk_vendor = adoptium
 bundled_jdk = 17.0.2+8
 
-checkstyle = 8.45.1
+checkstyle = 9.3
 
 # optional dependencies
 spatial4j         = 0.7