Skip to content

Commit 3b70818

Browse files
committed
Add support for errorprone 2.24.1 static analysis tool and Github Action to check for issues reported
1 parent 5c1f931 commit 3b70818

File tree

2 files changed

+108
-4
lines changed

2 files changed

+108
-4
lines changed

.github/workflows/errorprone.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Error Prone Analysis
19+
20+
on:
21+
push:
22+
branches: [ main ]
23+
pull_request:
24+
branches: [ main ]
25+
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
28+
cancel-in-progress: true
29+
30+
permissions:
31+
contents: read
32+
33+
jobs:
34+
errorprone:
35+
runs-on: ubuntu-22.04
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Set up JDK 11
40+
uses: actions/setup-java@v4
41+
with:
42+
java-version: '11'
43+
distribution: 'adopt'
44+
architecture: x64
45+
cache: maven
46+
47+
- name: Run Error Prone Static Analysis (Strict Mode)
48+
run: |
49+
echo "::group::Error Prone Analysis"
50+
# Temporarily remove -XepAllErrorsAsWarnings to run in strict mode
51+
sed -i 's/-Xplugin:ErrorProne -XepAllErrorsAsWarnings/-Xplugin:ErrorProne/g' pom.xml
52+
mvn clean compile -DskipTests -T$(nproc) 2>&1 | tee errorprone.log
53+
BUILD_RESULT=$?
54+
echo "::endgroup::"
55+
exit $BUILD_RESULT
56+
continue-on-error: true
57+
58+
- name: Check for Error Prone Issues
59+
id: check-errors
60+
run: |
61+
if grep -q "error: \[" errorprone.log; then
62+
echo "has_errors=true" >> $GITHUB_OUTPUT
63+
echo "::error::Error Prone found issues in the code"
64+
echo ""
65+
echo "=== Error Prone Issues Found ==="
66+
grep -B 2 "error: \[" errorprone.log | head -50
67+
echo ""
68+
69+
# Create job summary
70+
echo "## ⚠️ Error Prone Analysis Failed" >> $GITHUB_STEP_SUMMARY
71+
echo "" >> $GITHUB_STEP_SUMMARY
72+
echo "Error Prone static analysis detected issues in this PR." >> $GITHUB_STEP_SUMMARY
73+
echo "" >> $GITHUB_STEP_SUMMARY
74+
echo "### Issues Found (first 50):" >> $GITHUB_STEP_SUMMARY
75+
echo '```' >> $GITHUB_STEP_SUMMARY
76+
grep -B 2 "error: \[" errorprone.log | head -50 >> $GITHUB_STEP_SUMMARY
77+
echo '```' >> $GITHUB_STEP_SUMMARY
78+
echo "" >> $GITHUB_STEP_SUMMARY
79+
echo "See the [Error Prone documentation](https://errorprone.info/) for details on each bug pattern." >> $GITHUB_STEP_SUMMARY
80+
else
81+
echo "has_errors=false" >> $GITHUB_OUTPUT
82+
echo "✅ No Error Prone issues found"
83+
84+
# Create success summary
85+
echo "## ✅ Error Prone Analysis Passed" >> $GITHUB_STEP_SUMMARY
86+
echo "" >> $GITHUB_STEP_SUMMARY
87+
echo "No issues detected by Error Prone static analysis." >> $GITHUB_STEP_SUMMARY
88+
fi
89+
90+
- name: Fail if errors found
91+
if: steps.check-errors.outputs.has_errors == 'true'
92+
run: exit 1
93+

pom.xml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<cs.surefire-plugin.version>2.22.2</cs.surefire-plugin.version>
8181
<cs.clover-maven-plugin.version>4.4.1</cs.clover-maven-plugin.version>
8282
<cs.exec-maven-plugin.version>3.2.0</cs.exec-maven-plugin.version>
83+
<cs.errorprone.version>2.24.1</cs.errorprone.version>
8384

8485
<!-- Logging versions -->
8586
<cs.log4j.version>2.19.0</cs.log4j.version>
@@ -1094,15 +1095,25 @@
10941095
<configuration>
10951096
<source>${cs.jdk.version}</source>
10961097
<target>${cs.jdk.version}</target>
1097-
<fork>true</fork>
1098-
<meminitial>128m</meminitial>
1099-
<maxmem>512m</maxmem>
1098+
<encoding>UTF-8</encoding>
11001099
<compilerArgs>
11011100
<arg>-XDignore.symbol.file=true</arg>
11021101
<arg>--add-opens=java.base/java.lang=ALL-UNNAMED</arg>
11031102
<arg>--add-exports=java.base/sun.security.x509=ALL-UNNAMED</arg>
11041103
<arg>--add-exports=java.base/sun.security.provider=ALL-UNNAMED</arg>
1104+
<arg>-XDcompilePolicy=simple</arg>
1105+
<arg>-Xplugin:ErrorProne -XepAllErrorsAsWarnings</arg>
11051106
</compilerArgs>
1107+
<annotationProcessorPaths>
1108+
<path>
1109+
<groupId>com.google.errorprone</groupId>
1110+
<artifactId>error_prone_core</artifactId>
1111+
<version>${cs.errorprone.version}</version>
1112+
</path>
1113+
</annotationProcessorPaths>
1114+
<fork>true</fork>
1115+
<meminitial>128m</meminitial>
1116+
<maxmem>512m</maxmem>
11061117
</configuration>
11071118
</plugin>
11081119
<plugin>
@@ -1452,4 +1463,4 @@
14521463
</build>
14531464
</profile>
14541465
</profiles>
1455-
</project>
1466+
</project>

0 commit comments

Comments
 (0)