Skip to content

Migrate InitializationTests to addSourceLines - #1694

Merged
msridhar merged 3 commits into
uber:masterfrom
abdeltaehass:agent/cleanup-initialization-add-source-lines
Aug 13, 2026
Merged

msridhar merged 3 commits into
uber:masterfrom
abdeltaehass:agent/cleanup-initialization-add-source-lines

Conversation

@abdeltaehass

@abdeltaehass abdeltaehass commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • replace the deprecated addSourceFile calls in InitializationTests with inline addSourceLines text blocks
  • factor the shared Util.java source into a helper, as requested in the issue discussion
  • remove the four testdata files that are no longer referenced and the obsolete class-level deprecation suppression

Part of #1425.

Testing

  • ./gradlew :nullaway:spotlessJavaApply -Pspotless.ratchet.from=HEAD
  • ./gradlew :nullaway:test --tests "com.uber.nullaway.InitializationTests"

AI usage disclosure

I used OpenAI Codex to help identify the affected calls, migrate the existing test sources into text blocks, factor the shared source in response to maintainer feedback, run formatting and targeted tests, and draft this PR description. I personally reviewed the full diff and attest that I have read and understood all changes in this PR.

Summary by CodeRabbit

  • Tests
    • Consolidated initialization and read-before-initialization scenarios directly into the test suite.
    • Expanded coverage for field and static initialization, initializer methods, framework annotations, suppression, nested classes, casts, assertions, and early field reads.
    • Removed redundant external test fixtures while preserving and broadening diagnostic coverage.
    • Improved consistency and maintainability of initialization-related validation.

@CLAassistant

CLAassistant commented Aug 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@abdeltaehass
abdeltaehass marked this pull request as ready for review August 11, 2026 16:47
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1e15c5e0-d0ee-45b3-8cd6-885ab14b93b7

📥 Commits

Reviewing files that changed from the base of the PR and between 55f5d1f and 0b68eaf.

📒 Files selected for processing (1)
  • nullaway/src/test/java/com/uber/nullaway/InitializationTests.java

Walkthrough

InitializationTests now embeds field-initialization and read-before-initialization fixtures through addSourceLines. A shared Util source supports both read-before-initialization tests. The embedded cases cover constructors, initializer methods, static and instance initialization, nested classes, suppression, inheritance, monotonic fields, helper calls, casts, assertions, and expected diagnostics. The corresponding external testdata files were deleted.

Possibly related PRs

  • uber/NullAway#1426: Replaces external testdata fixtures with inline sources and deletes the corresponding files.
  • uber/NullAway#1517: Moves external fixtures into embedded addSourceLines sources.
  • uber/NullAway#1695: Migrates test fixtures from external resources to inline addSourceLines definitions.

Suggested reviewers: msridhar, yuxincs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: migrating InitializationTests to inline addSourceLines fixtures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@msridhar msridhar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Please see comments below and remove all license headers within tests.

return helper.addSourceLines(
"Util.java",
"""
/*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we align the top-level source lines with the opening and closing """ delimiters?

Comment on lines +19 to +39
* Copyright (c) 2017 Uber Technologies, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of the license header here; a license header on the top-level source file should suffice

.addSourceLines(
"CheckFieldInitPositiveCases.java",
"""
/*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about source header

msridhar pushed a commit that referenced this pull request Aug 11, 2026
…rkTests (#1695)

## Summary

- Replace the nine `addSourceFile` calls for annotation stubs in
`FrameworkTests` (four Spring Boot mock annotations, four Mockito
annotations, `InjectWireMock`) with inline `addSourceLines` text blocks.
- Delete the nine now-unreferenced testdata files.
- Factor the repeated `java.lang.annotation` imports and
`@Target`/`@Retention` boilerplate into class constants, since the nine
stubs otherwise only differ by package and by which of three `@Target`
styles and one annotation declaration they use.

The class-level `@SuppressWarnings("deprecation")` is retained: eight
other `addSourceFile` calls remain in this file (Lombok, native
models/androidstubs, Rx, stream support), so the annotation is still
load-bearing — removing it causes a `-Werror` build failure on those
remaining calls. I verified this by temporarily deleting it and
recompiling.

No overlap with #1694, which is scoped to `InitializationTests.java` and
its testdata files.

Part of #1425.

## Testing

- `./gradlew :nullaway:test --tests "com.uber.nullaway.FrameworkTests"`
- `./gradlew :nullaway:test` (full module suite: 911 tests, 0 failures)
- Verified each converted stub is load-bearing (not shadowed by a real
dependency on the test classpath) by temporarily corrupting its
package/`@Target` and confirming the corresponding test fails to compile
or fails its assertions, then restoring it.

## AI usage disclosure

> I used Claude Code for this PR. The first commit — converting the nine
`addSourceFile` calls to inline `addSourceLines` text blocks and
deleting the now-unreferenced testdata files — was a mechanical,
one-shot conversion. I reviewed that diff, then noticed significant
duplication across the inlined text blocks (repeated imports and
`@Target`/`@Retention` lines) and directed Claude to factor that
boilerplate into shared constants, which became the second commit. I
personally reviewed and understood both commits before pushing.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Tests**
- Updated framework validation tests to generate Spring Boot, Mockito,
and WireMock annotation fixtures during test execution.
- Removed redundant test-only annotation source files while preserving
coverage for supported annotation scenarios.
- Consolidated shared fixture definitions to improve consistency across
framework integration tests.

- **Chores**
- Simplified test resources and reduced maintenance overhead for
annotation-based test fixtures.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Copy link
Copy Markdown
Contributor Author

Addressed all review feedback in 0b68eaf: removed the embedded license headers, aligned the shared source text block, and updated the line-sensitive diagnostic expectations. ./gradlew :nullaway:spotlessJavaApply -Pspotless.ratchet.from=HEAD and ./gradlew :nullaway:test --tests "com.uber.nullaway.InitializationTests" both pass. Ready for re-review—thanks!

@abdeltaehass
abdeltaehass requested a review from msridhar August 12, 2026 16:34

@msridhar msridhar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@msridhar
msridhar enabled auto-merge (squash) August 13, 2026 00:47
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.89%. Comparing base (f3f7c9b) to head (f53808c).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1694   +/-   ##
=========================================
  Coverage     87.89%   87.89%           
  Complexity     3173     3173           
=========================================
  Files           109      109           
  Lines         10755    10755           
  Branches       2173     2173           
=========================================
  Hits           9453     9453           
  Misses          617      617           
  Partials        685      685           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msridhar
msridhar merged commit 56bd5ad into uber:master Aug 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants