-
Notifications
You must be signed in to change notification settings - Fork 42
Add SpotBugs static analysis target, workflow, and fix reported issues #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
20b10ce
Testing: add 'ant spotbugs' target and SpotBugs exclusion filter
cconlon dbcdcf3
JNI/JSSE: Fix bugs found by SpotBugs
cconlon bd8606d
JNI/JSSE: Fix visibility and access modifiers found by SpotBugs
cconlon fc867c3
JNI/JSSE: Fix threading issues found by SpotBugs
cconlon 6b59646
JNI/JSSE: Code cleanup from SpotBugs review
cconlon b51439c
JNI/JSSE: Add SpotBugs exclusions for reviewed warnings
cconlon 6d58949
Testing: Add SpotBugs GitHub Actions workflow
cconlon 9fdc7ee
Testing: Fix Android emulator flaky boot in CI, upgrade emulator-runn…
cconlon c362bd3
Testing: Skip IP name constraint tests on Windows (native XINET_PTON …
cconlon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| name: SpotBugs Static Analysis | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ '*' ] | ||
| paths: | ||
| - '**/*.java' | ||
| - 'build.xml' | ||
| - 'spotbugs-exclude.xml' | ||
|
|
||
| jobs: | ||
| spotbugs: | ||
| runs-on: ubuntu-latest | ||
| name: Run SpotBugs | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Java 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '17' | ||
|
|
||
| - name: Set up Ant | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y ant | ||
|
|
||
| - name: Download JUnit | ||
| run: | | ||
| mkdir -p /tmp/junit | ||
| wget -q -P /tmp/junit \ | ||
| "https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar" | ||
| EXPECTED_SHA="8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3" | ||
| echo "${EXPECTED_SHA} /tmp/junit/junit-4.13.2.jar" | sha256sum -c - | ||
| echo "JUNIT_HOME=/tmp/junit" >> $GITHUB_ENV | ||
|
|
||
| - name: Download and set up SpotBugs | ||
| run: | | ||
| SPOTBUGS_VERSION="4.9.3" | ||
| wget -q "https://github.com/spotbugs/spotbugs/releases/download/${SPOTBUGS_VERSION}/spotbugs-${SPOTBUGS_VERSION}.tgz" | ||
|
cconlon marked this conversation as resolved.
|
||
| EXPECTED_SHA="d464d56050cf1dbda032e9482e1188f7cd7b7646eaff79c2e6cbe4d6822f4d9f" | ||
| echo "${EXPECTED_SHA} spotbugs-${SPOTBUGS_VERSION}.tgz" | sha256sum -c - | ||
| tar xzf "spotbugs-${SPOTBUGS_VERSION}.tgz" | ||
| echo "SPOTBUGS_HOME=${GITHUB_WORKSPACE}/spotbugs-${SPOTBUGS_VERSION}" >> $GITHUB_ENV | ||
|
|
||
| - name: Run SpotBugs | ||
| run: | | ||
|
cconlon marked this conversation as resolved.
|
||
| ant spotbugs | ||
|
|
||
| - name: Check for SpotBugs warnings | ||
| if: always() | ||
| run: | | ||
| REPORT_XML="build/reports/spotbugs.xml" | ||
| if [ ! -f "$REPORT_XML" ]; then | ||
| echo "SpotBugs XML report not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Extract warning count from XML report | ||
| COUNT=$(python3 -c " | ||
| import xml.etree.ElementTree as ET | ||
| tree = ET.parse('$REPORT_XML') | ||
| root = tree.getroot() | ||
| bugs = root.findall('.//BugInstance') | ||
| print(len(bugs)) | ||
| ") | ||
|
|
||
| if [ "$COUNT" -eq 0 ]; then | ||
| echo "==================================" | ||
| echo "SpotBugs: 0 warnings found" | ||
| echo "==================================" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "==================================" | ||
| echo "SpotBugs: $COUNT warning(s) found" | ||
| echo "==================================" | ||
| echo "" | ||
|
|
||
| # Print each warning from XML | ||
| python3 -c " | ||
| import xml.etree.ElementTree as ET | ||
| tree = ET.parse('$REPORT_XML') | ||
| root = tree.getroot() | ||
| for bug in root.findall('.//BugInstance'): | ||
| bug_type = bug.get('type', 'UNKNOWN') | ||
| priority = bug.get('priority', 'N/A') | ||
| long_msg = bug.find('LongMessage') | ||
| msg = long_msg.text.strip() if long_msg is not None and long_msg.text else '' | ||
| src = bug.find('.//SourceLine') | ||
| loc = '' | ||
| if src is not None: | ||
| loc = src.get('sourcefile', '') + ':' + src.get('start', '') | ||
| print(f'[P{priority}] {bug_type}') | ||
| if msg: | ||
| print(f' {msg[:200]}') | ||
| if loc: | ||
| print(f' at {loc}') | ||
| print() | ||
| " | ||
|
|
||
| exit 1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.