From 671ac41624485922d02445eb3eaadcfd777ed15d Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 29 Aug 2024 14:50:01 -0700 Subject: [PATCH 1/8] Update ci.yml to use javadoc:javadoc Instead of javadoc:aggregate, to catch issues like https://github.com/google/error-prone/commit/5bf91fb051bce74517456a35e798c44c331d7da2 h/t/ @cpovirk --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 321b7e4ae34..b96f647bd03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,7 +92,7 @@ jobs: # only generate javadoc on JDKs with the fix for https://bugs.openjdk.org/browse/JDK-8241780 if: ${{ matrix.java >= 15 }} shell: bash - run: mvn -P '!examples' javadoc:aggregate + run: mvn -P '!examples' javadoc:javadoc publish_snapshot: name: 'Publish snapshot' From dab4089256a0d5b9658afebc6f66c267c9035dc9 Mon Sep 17 00:00:00 2001 From: ghm Date: Fri, 30 Aug 2024 12:33:49 -0700 Subject: [PATCH 2/8] Add the name of the method to the diagnostic message for MemberName. PiperOrigin-RevId: 669411448 --- .../google/errorprone/bugpatterns/MemberName.java | 14 +++++++++----- .../errorprone/bugpatterns/MemberNameTest.java | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java b/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java index d0c84aecae1..9506d9ed517 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MemberName.java @@ -132,12 +132,13 @@ public Description matchMethod(MethodTree tree, VisitorState state) { boolean fixable = !suggested.equals(name) && canBeRemoved(symbol, state); String diagnostic = "Methods and non-static variables should be named in lowerCamelCase" - + (suggested.equals(renamed) ? "" : INITIALISM_DETAIL); + + (suggested.equals(renamed) ? "" : INITIALISM_DETAIL) + + ", but " + + symbol.getSimpleName() + + " is not"; return buildDescription(tree) .setMessage( - fixable - ? diagnostic - : diagnostic + String.format("; did you" + " mean '%s'?", suggested)) + fixable ? diagnostic : diagnostic + String.format("; did you mean '%s'?", suggested)) .addFix(fixable ? renameMethodWithInvocations(tree, suggested, state) : emptyFix()) .build(); } @@ -183,7 +184,10 @@ public Description matchVariable(VariableTree tree, VisitorState state) { boolean fixable = !suggested.equals(name) && canBeRenamed(symbol); String diagnostic = (isStaticVariable(symbol) ? STATIC_VARIABLE_FINDING : message()) - + (suggested.equals(renamed) ? "" : INITIALISM_DETAIL); + + (suggested.equals(renamed) ? "" : INITIALISM_DETAIL) + + ", but " + + symbol.getSimpleName() + + " is not"; return buildDescription(tree) .setMessage( fixable diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java index a1da16d7349..c1df079c152 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MemberNameTest.java @@ -202,7 +202,7 @@ public void nameWithLeadingUppercase() { .addSourceLines( "Test.java", "class Test {", - " // BUG: Diagnostic contains:", + " // BUG: Diagnostic contains: foo", " private int Foo;", " int get() {", " return Foo;", @@ -347,7 +347,7 @@ public void methodWithUnderscores_notOverriddenFromGeneratedSupertype_bug() { .addSourceLines( "Test.java", "class Test extends Base {", - " // BUG: Diagnostic contains:", + " // BUG: Diagnostic contains: get_more", " public int get_more() {", " return 0;", " }", @@ -361,7 +361,7 @@ public void nonConformantOverride_nameMatchesSuper_ignored() { .addSourceLines( "Base.java", "interface Base {", - " // BUG: Diagnostic contains:", + " // BUG: Diagnostic contains: a_b", " void foo(int a_b);", "}") .addSourceLines( From 494e2c604df4c4ab84428896f53a15c9d9de7d7b Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Mon, 9 Sep 2024 09:55:27 -0700 Subject: [PATCH 3/8] Don't perform the inlining if parameter names are stripped. #inlineme PiperOrigin-RevId: 672578943 --- .../errorprone/bugpatterns/inlineme/Inliner.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java index 5b234814c50..197b041e34c 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/inlineme/Inliner.java @@ -236,11 +236,18 @@ && stringContainsComments(state.getSourceForNode(tree), state.context)) { } for (int i = 0; i < varNames.size(); i++) { + String varName = varNames.get(i); + + // If the parameter names are missing (b/365094947), don't perform the inlining. + if (varName.matches("arg[0-9]+")) { + return Description.NO_MATCH; + } + // The replacement logic below assumes the existence of another token after the parameter // in the replacement string (ex: a trailing parens, comma, dot, etc.). However, in the case // where the replacement is _just_ one parameter, there isn't a trailing token. We just make // the direct replacement here. - if (replacement.equals(varNames.get(i))) { + if (replacement.equals(varName)) { replacement = callingVars.get(i); break; } @@ -252,7 +259,7 @@ && stringContainsComments(state.getSourceForNode(tree), state.context)) { String capturePrefixForVarargs = terminalVarargsReplacement ? "(?:,\\s*)?" : "\\b"; // We want to avoid replacing a method invocation with the same name as the method. var extractArgAndNextToken = - Pattern.compile(capturePrefixForVarargs + Pattern.quote(varNames.get(i)) + "\\b([^(])"); + Pattern.compile(capturePrefixForVarargs + Pattern.quote(varName) + "\\b([^(])"); String replacementResult = Matcher.quoteReplacement(terminalVarargsReplacement ? "" : callingVars.get(i)) + "$1"; Matcher matcher = extractArgAndNextToken.matcher(replacement); From 4b5ee1eed4cef7ac47514f5fdb4a0eef8e077a8a Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 11 Sep 2024 09:26:48 -0700 Subject: [PATCH 4/8] Update ci.yml: always set up JDK 17 --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b96f647bd03..7e013d3c287 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,12 @@ jobs: java-version: 11 distribution: 'zulu' cache: 'maven' + - name: 'Set up JDK 17' + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'zulu' + cache: 'maven' - name: 'Set up JDK 24 from jdk.java.net' uses: oracle-actions/setup-java@v1 with: From 4e0b19cea5da91f3e9080cb8535839902bfdee3a Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 11 Sep 2024 09:56:39 -0700 Subject: [PATCH 5/8] Start using Java > 11 language features in Error Prone tests This is a first step towards raising the minimum supported JDK version Error Prone to JDK 17. PiperOrigin-RevId: 673432814 --- check_api/pom.xml | 2 +- .../errorprone/bugpatterns/FinallyTest.java | 23 +++++++++++-------- pom.xml | 6 ++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/check_api/pom.xml b/check_api/pom.xml index 0824e406034..8a24c1a48fd 100644 --- a/check_api/pom.xml +++ b/check_api/pom.xml @@ -168,7 +168,7 @@ default-compile - 11 + 17 diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FinallyTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FinallyTest.java index 621ae03f66e..08b32015615 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FinallyTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FinallyTest.java @@ -55,15 +55,20 @@ public void lambda() { compilationHelper .addSourceLines( "Test.java", - "class Test {", - " void f() {", - " try {", - " } catch (Throwable t) {", - " } finally {", - " Runnable r = () -> { return; };", - " }", - " }", - "}") + """ + class Test { + void f() { + try { + } catch (Throwable t) { + } finally { + Runnable r = + () -> { + return; + }; + } + } + } + """) .doTest(); } } diff --git a/pom.xml b/pom.xml index 2181e204e5b..97697041501 100644 --- a/pom.xml +++ b/pom.xml @@ -182,8 +182,8 @@ maven-compiler-plugin 3.13.0 - 11 - 11 + 17 + 17 --add-exports=java.base/jdk.internal.javac=ALL-UNNAMED @@ -284,7 +284,7 @@ - 11 + 17 24 From a9ff9b1c1afc0164794fe9cd1209335884455e45 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 11 Sep 2024 10:08:02 -0700 Subject: [PATCH 6/8] Update ci.yml: remove JDK 11 --- .github/workflows/ci.yml | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e013d3c287..bb49464245e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-latest ] - java: [ 21, 17, 11 ] + java: [ 21, 17 ] experimental: [ false ] # Only test on macos and windows with a single recent JDK to avoid a # combinatorial explosion of test configurations. @@ -52,12 +52,6 @@ jobs: access_token: ${{ github.token }} - name: 'Check out repository' uses: actions/checkout@v3 - - name: 'Set up JDK 11' - uses: actions/setup-java@v4 - with: - java-version: 11 - distribution: 'zulu' - cache: 'maven' - name: 'Set up JDK 17' uses: actions/setup-java@v4 with: @@ -90,13 +84,7 @@ jobs: - name: 'Test' shell: bash run: mvn test -B - - name: 'Test compatibility with JDK 11' - if: ${{ matrix.java == 17 }} - shell: bash - run: mvn test -B -Dsurefire.jdk-toolchain-version=11 - name: 'Javadoc' - # only generate javadoc on JDKs with the fix for https://bugs.openjdk.org/browse/JDK-8241780 - if: ${{ matrix.java >= 15 }} shell: bash run: mvn -P '!examples' javadoc:javadoc @@ -117,9 +105,7 @@ jobs: - name: 'Set up JDK 17' uses: actions/setup-java@v4 with: - java-version: | - 11 - 17 + java-version: 17 distribution: 'zulu' cache: 'maven' server-id: ossrh @@ -151,9 +137,7 @@ jobs: - name: 'Set up JDK 17' uses: actions/setup-java@v4 with: - java-version: | - 11 - 17 + java-version: 17 distribution: 'zulu' cache: 'maven' - name: 'Generate latest docs' From 655bdc4311378df4b94f3e300e5d5ec247c83ac8 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 11 Sep 2024 10:08:32 -0700 Subject: [PATCH 7/8] Update release.yml: remove JDK 11 --- .github/workflows/release.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b76cfd0cc48..d0eb2e627c6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,9 +26,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v4 with: - java-version: | - 11 - 17 + java-version: 17 distribution: 'zulu' cache: 'maven' server-id: ossrh From 0fe0961648101a4320928e3b336c85bd835d4e07 Mon Sep 17 00:00:00 2001 From: cushon Date: Wed, 11 Sep 2024 18:08:22 +0000 Subject: [PATCH 8/8] Release Error Prone 2.32.0 --- annotation/pom.xml | 2 +- annotations/pom.xml | 2 +- check_api/pom.xml | 2 +- core/pom.xml | 2 +- docgen/pom.xml | 2 +- docgen_processor/pom.xml | 2 +- pom.xml | 2 +- refaster/pom.xml | 2 +- test_helpers/pom.xml | 2 +- type_annotations/pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/annotation/pom.xml b/annotation/pom.xml index fbbba7c5524..d86385c7c3a 100644 --- a/annotation/pom.xml +++ b/annotation/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 @BugPattern annotation diff --git a/annotations/pom.xml b/annotations/pom.xml index 62ebfe88a40..622d0a955c1 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 error-prone annotations diff --git a/check_api/pom.xml b/check_api/pom.xml index 8a24c1a48fd..e04acfdc1ac 100644 --- a/check_api/pom.xml +++ b/check_api/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 error-prone check api diff --git a/core/pom.xml b/core/pom.xml index 41f23273342..8e35bcce13c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 error-prone library diff --git a/docgen/pom.xml b/docgen/pom.xml index 8ee00587502..6d656bafdec 100644 --- a/docgen/pom.xml +++ b/docgen/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 Documentation tool for generating Error Prone bugpattern documentation diff --git a/docgen_processor/pom.xml b/docgen_processor/pom.xml index 7d97a4cb4ca..cd74cae3510 100644 --- a/docgen_processor/pom.xml +++ b/docgen_processor/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 JSR-269 annotation processor for @BugPattern annotation diff --git a/pom.xml b/pom.xml index 97697041501..cb723618b8c 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ Error Prone parent POM com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 pom Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time. diff --git a/refaster/pom.xml b/refaster/pom.xml index 968b0c2bae4..9028d14048f 100644 --- a/refaster/pom.xml +++ b/refaster/pom.xml @@ -19,7 +19,7 @@ error_prone_parent com.google.errorprone - 1.0-HEAD-SNAPSHOT + 2.32.0 4.0.0 diff --git a/test_helpers/pom.xml b/test_helpers/pom.xml index 66b12d308c3..844b366cdd0 100644 --- a/test_helpers/pom.xml +++ b/test_helpers/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 error-prone test helpers diff --git a/type_annotations/pom.xml b/type_annotations/pom.xml index 365123af188..5d01eb9d992 100644 --- a/type_annotations/pom.xml +++ b/type_annotations/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - 1.0-HEAD-SNAPSHOT + 2.32.0 error-prone type annotations