Repository navigation
Refactor CoreTests and UnannotatedTests to use addSourceLines and inline test data - #1426
Conversation
WalkthroughReplaces deprecated CompilationTestHelper#addSourceFile calls with addSourceLines in UnannotatedTests and CoreTests by inlining several test source files (AnnotatedClass, TestAnnot, Shape_Stuff, Shape_Stuff2, and unannotated/UnannotatedClass) into the test methods and deletes the corresponding test resource files. Removes the class-level Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
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. Comment |
msridhar
left a comment
There was a problem hiding this comment.
Thanks for the contribution @cobayo!
Could you use text blocks instead of comma-separated strings for the test data? We plan to shift to using text blocks for test data everywhere, see #1424. You can use the changes there as an example of how the text blocks should look.
|
Also @cobayo it looks like these files are used in other tests, that's why CI is failing. So you'll need to do this fix in more places for it to be mergeable. |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (10)
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/resources/com/uber/nullaway/testdata/CapturingScopes.javanullaway/src/test/resources/com/uber/nullaway/testdata/CheckAssertSupportNegativeCases.javanullaway/src/test/resources/com/uber/nullaway/testdata/CheckAssertSupportPositiveCases.javanullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayAnonymousClass.javanullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayNegativeCases.javanullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayPositiveCases.javanullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayTryFinallyCases.javanullaway/src/test/resources/com/uber/nullaway/testdata/OtherStuff.java
💤 Files with no reviewable changes (8)
- nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayPositiveCases.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayTryFinallyCases.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/CapturingScopes.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/OtherStuff.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayNegativeCases.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/CheckAssertSupportNegativeCases.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayAnonymousClass.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/CheckAssertSupportPositiveCases.java
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-08-29T18:41:43.584Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1259
File: jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java:318-321
Timestamp: 2025-08-29T18:41:43.584Z
Learning: Classes annotated with NullMarked are analyzed by NullAway even if they are not in packages specified by the AnnotatedPackages configuration. The NullMarked annotation guarantees NullAway analysis.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Run only the tests for the main NullAway module using `./gradlew :nullaway:test` unless specifically asked to run tests in a different module
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Use the `--tests` flag with gradle to run specific test classes or methods, e.g., `./gradlew :nullaway:test --tests "com.uber.nullaway.NullAwayTest"`
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
📚 Learning: 2025-10-29T23:56:18.236Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1316
File: jdk-javac-plugin/src/main/java/com/uber/nullaway/javacplugin/NullnessAnnotationSerializer.java:261-293
Timestamp: 2025-10-29T23:56:18.236Z
Learning: In NullAway's jdk-javac-plugin NullnessAnnotationSerializer, type variable bounds with annotations (e.g., `T extends Nullable Object`) are checked at their declaration sites by the typeParamHasAnnotation method for both class-level and method-level type parameters. The hasJSpecifyAnnotationDeep method is designed to check type uses (return types, parameters, etc.) and does not need a TYPEVAR case because type variable declaration bounds are already handled separately.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
🧬 Code graph analysis (1)
nullaway/src/test/java/com/uber/nullaway/CoreTests.java (4)
nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java (1)
SuppressWarnings(6-1309)nullaway/src/test/java/com/uber/nullaway/ContractsTests.java (1)
SuppressWarnings(6-597)nullaway/src/test/java/com/uber/nullaway/ThriftTests.java (1)
SuppressWarnings(6-193)nullaway/src/test/java/com/uber/nullaway/InitializationTests.java (1)
SuppressWarnings(6-185)
🔇 Additional comments (10)
nullaway/src/test/java/com/uber/nullaway/CoreTests.java (8)
36-509: LGTM! Test data successfully inlined.The migration from
addSourceFiletoaddSourceLineswith inline test data is clean and consistent with the PR objectives.
515-554: LGTM! Test data successfully inlined.The migration to inline test data is consistent with the PR approach.
560-1557: LGTM! Multiple test data files successfully inlined.The migration of NullAwayNegativeCases.java, OtherStuff.java, TestAnnot.java, and UnannotatedClass.java to inline sources is clean and maintains test functionality.
1563-1590: LGTM! Test data successfully inlined.
1601-1645: LGTM! Test data successfully inlined.
1857-1891: LGTM! Util.java test data successfully inlined.
2051-2190: LGTM! CapturingScopes.java test data successfully inlined.
2441-2875: LGTM! NullAwayTryFinallyCases.java test data successfully inlined.nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java (2)
6-78: LGTM! Class annotation removed and test data successfully inlined.The removal of the class-level
@SuppressWarnings("deprecation")annotation aligns with the PR objectives, and the migration of Shape_Stuff.java, Shape_Stuff2.java, AnnotatedClass.java, and TestAnnot.java to inline sources is clean.
135-166: LGTM! UnannotatedClass.java test data successfully inlined.The migration to inline test data is consistent with the PR approach.
|
Thank you for the guidance, @msridhar! Regarding other occurrences of addSourceFile in the codebase: would you like me to address all of them across the entire project in this PR to align with the new policy (#1424), or should I keep this PR focused only on the tests related to the files I've already modified? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1426 +/- ##
=========================================
Coverage 88.37% 88.37%
Complexity 2667 2667
=========================================
Files 97 97
Lines 8853 8853
Branches 1773 1773
=========================================
Hits 7824 7824
Misses 512 512
Partials 517 517 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
msridhar
left a comment
There was a problem hiding this comment.
@cobayo sorry, there are some new conflicts with the master branch since we merged #1424. Could you fix? In relation to your question, let's limit this PR to these test files for now and not do the whole project. I think we'll need follow-up tasks to split up some of these tests into smaller tests, as some of the test data files are quite large. We could also split a class like CoreTests into multiple test classes, each containing the smaller tests. That could also speed up running the test suite (since Gradle will run test classes in parallel but not tests within a class). But that's all for follow up.
|
@msridhar Following your suggestion, I've limited the changes to these specific test files for now. The physical test data files have been removed as they are now fully inlined. CI should be green now! |
msridhar
left a comment
There was a problem hiding this comment.
Overall this looks good. I have a couple of nitpicks on formatting. If they are for some reason too hard to fix let me know
| .addSourceLines( | ||
| "NullAwayPositiveCases.java", | ||
| """ | ||
| package com.uber.nullaway.testdata; |
There was a problem hiding this comment.
Could we get the indentation of the code to always align vertically with the """ that starts the text block? I think you could do this, e.g., by highlighting the test data code in IntelliJ and doing SHIFT+TAB until it's aligned
| // BUG: Diagnostic contains: passing @Nullable parameter 'q' where | ||
| return new TestAnon3(q) {}; | ||
| } | ||
| }""") |
There was a problem hiding this comment.
Also, could we always have a trailing newline, so the ending """ aligns vertically with the beginning """ and we have a close paren right after? Formatting like line 552 of the file is what I'm hoping for
Refactor UnannotatedTests to inline multiple test data files Replaced addSourceFile with addSourceLines in all test cases. Inlined Shape_Stuff.java, Shape_Stuff2.java, AnnotatedClass.java, and TestAnnot.java. Deleted the original source files from testdata directory. Removed unnecessary @SuppressWarnings(deprecation) annotations.
There was a problem hiding this comment.
Actionable comments posted: 2
Fix all issues with AI Agents 🤖
In @nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java:
- Around line 33-54: Fix indentation inside the Shape_Stuff2.java test text
block: remove the extra leading space before the class comment line inside the
block (the "/** to test exclusions functionality */" line) so it aligns with the
package declaration and class declaration, and adjust the final closing brace so
it aligns with the "public class Shape_Stuff2" opening (remove excessive leading
spaces before the last "}" ). Ensure inner class C and its members keep their
existing relative indentation.
- Around line 140-170: The inlined UnannotatedClass.java text block has
inconsistent indentation; fix it by aligning class members and Javadoc/method
bodies to a consistent indentation level inside class UnannotatedClass: indent
"private Object field;" and "@Nullable public Object maybeNull;" as class
members, normalize indentation of the constructor and the static methods foo()
and bar(), and remove the excessive leading spaces before the class closing
brace and the closing triple-quote so the ending brace aligns with the class
declaration and the closing """ aligns with the .addSourceLines( call. Ensure
Javadoc lines are indented to match their methods.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/resources/com/uber/nullaway/testdata/AnnotatedClass.javanullaway/src/test/resources/com/uber/nullaway/testdata/Shape_Stuff.javanullaway/src/test/resources/com/uber/nullaway/testdata/TestAnnot.javanullaway/src/test/resources/com/uber/nullaway/testdata/excluded/Shape_Stuff2.javanullaway/src/test/resources/com/uber/nullaway/testdata/unannotated/UnannotatedClass.java
💤 Files with no reviewable changes (5)
- nullaway/src/test/resources/com/uber/nullaway/testdata/unannotated/UnannotatedClass.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/excluded/Shape_Stuff2.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/TestAnnot.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/AnnotatedClass.java
- nullaway/src/test/resources/com/uber/nullaway/testdata/Shape_Stuff.java
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Run only the tests for the main NullAway module using `./gradlew :nullaway:test` unless specifically asked to run tests in a different module
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
📚 Learning: 2025-08-29T18:41:43.584Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1259
File: jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java:318-321
Timestamp: 2025-08-29T18:41:43.584Z
Learning: Classes annotated with NullMarked are analyzed by NullAway even if they are not in packages specified by the AnnotatedPackages configuration. The NullMarked annotation guarantees NullAway analysis.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Use the `--tests` flag with gradle to run specific test classes or methods, e.g., `./gradlew :nullaway:test --tests "com.uber.nullaway.NullAwayTest"`
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
📚 Learning: 2025-10-29T23:56:18.236Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1316
File: jdk-javac-plugin/src/main/java/com/uber/nullaway/javacplugin/NullnessAnnotationSerializer.java:261-293
Timestamp: 2025-10-29T23:56:18.236Z
Learning: In NullAway's jdk-javac-plugin NullnessAnnotationSerializer, type variable bounds with annotations (e.g., `T extends Nullable Object`) are checked at their declaration sites by the typeParamHasAnnotation method for both class-level and method-level type parameters. The hasJSpecifyAnnotationDeep method is designed to check type uses (return types, parameters, etc.) and does not need a TYPEVAR case because type variable declaration bounds are already handled separately.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
🔇 Additional comments (2)
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java (2)
11-32: LGTM: Migration to addSourceLines with inline test data is correct.The refactoring successfully addresses the deprecation of
addSourceFile()by:
- Using
addSourceLines()with Java text blocks for inline test data- Maintaining test semantics while eliminating external file dependencies
- Making tests more self-contained and maintainable
This approach aligns with the PR objectives and modern Java testing best practices.
Also applies to: 33-54, 55-67, 68-78, 140-170
11-79: Verification confirmed: no other tests reference the deleted test data files.The search for references to Shape_Stuff.java, Shape_Stuff2.java, AnnotatedClass.java, TestAnnot.java, and UnannotatedClass.java across the codebase returned no matches. The developer's claim that all test dependencies on the deleted files have been resolved is accurate.
|
@msridhar As you suggested, this keeps the PR more focused and easier to review. I’ve ensured that the specific test files I removed are no longer referenced. Ready for another look! |
Fix indentation
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI Agents
In @nullaway/src/test/java/com/uber/nullaway/CoreTests.java:
- Around line 52-62: The multi-line string passed to addSourceLines for
"TestAnnot.java" is not indented to align with the opening triple-quote ("""),
so adjust the indentation of every line inside that text block to match the
column of the opening """; locate the addSourceLines call that contains
"TestAnnot.java" and re-indent the package, imports, @Retention and public
@interface TestAnnot lines to the same indentation level as the opening """
(matching style used in testGenericAnonymousInner).
- Around line 63-92: Reformat the multi-line string for "UnannotatedClass.java"
so its content lines align vertically with the opening triple-quote: remove the
extra leading spaces before the first package line and ensure internal
indentation is consistent (e.g., 2 spaces per block level) for class body,
fields, constructor, and the Javadoc/methods (foo and bar); also remove the
extra leading space before the final closing brace and the closing triple-quote
so the block matches the other text blocks in the file.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
nullaway/src/test/java/com/uber/nullaway/CoreTests.java
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Run only the tests for the main NullAway module using `./gradlew :nullaway:test` unless specifically asked to run tests in a different module
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-08-29T18:41:43.584Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1259
File: jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java:318-321
Timestamp: 2025-08-29T18:41:43.584Z
Learning: Classes annotated with NullMarked are analyzed by NullAway even if they are not in packages specified by the AnnotatedPackages configuration. The NullMarked annotation guarantees NullAway analysis.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/CoreTests.java
Fix indentation
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java (1)
11-170: Consider automating the indentation fixes across all text blocks.Since multiple text blocks in both test files have the same indentation issue, would you like me to generate a comprehensive fix that addresses all the indentation inconsistencies at once? This would ensure consistent formatting across all the newly inlined test data blocks.
🤖 Fix all issues with AI Agents
In @nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java:
- Around line 55-67: Re-indent the multiline string passed to addSourceLines so
every line of the Java snippet is aligned with the opening triple-quote (""")
indentation; locate the addSourceLines call containing the "AnnotatedClass.java"
snippet and adjust the inner block (class AnnotatedClass, its Javadoc,
@TestAnnot, method foo, and statements) so leading spaces match the column of
the opening """, preserving existing content and line breaks.
- Around line 68-78: The indented Java source in the addSourceLines call for
"TestAnnot.java" is not aligned with the opening triple-quote; re-indent the
lines inside the text block so their left edge lines up with the opening """
(i.e., remove the extra leading spaces before "package
com.uber.nullaway.testdata;" and all subsequent lines) so the block's content is
vertically aligned with the opening delimiter in the addSourceLines call.
- Around line 11-32: The triple-quoted source block passed to addSourceLines for
"Shape_Stuff.java" is not indented to align with the opening """; re-indent the
entire string literal so its first line and subsequent lines align vertically
with the opening triple quotes, preserving the existing content (class
Shape_Stuff, nested class C, callee, and doBadStuff) and keeping internal
indentation relative to each other.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
nullaway/src/test/java/com/uber/nullaway/CoreTests.javanullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-08-29T18:41:43.584Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1259
File: jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java:318-321
Timestamp: 2025-08-29T18:41:43.584Z
Learning: Classes annotated with NullMarked are analyzed by NullAway even if they are not in packages specified by the AnnotatedPackages configuration. The NullMarked annotation guarantees NullAway analysis.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Run only the tests for the main NullAway module using `./gradlew :nullaway:test` unless specifically asked to run tests in a different module
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-08-28T04:54:20.953Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.javanullaway/src/test/java/com/uber/nullaway/CoreTests.java
📚 Learning: 2025-11-25T22:43:06.446Z
Learnt from: CR
Repo: uber/NullAway PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T22:43:06.446Z
Learning: Use the `--tests` flag with gradle to run specific test classes or methods, e.g., `./gradlew :nullaway:test --tests "com.uber.nullaway.NullAwayTest"`
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
📚 Learning: 2025-10-29T23:56:18.236Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1316
File: jdk-javac-plugin/src/main/java/com/uber/nullaway/javacplugin/NullnessAnnotationSerializer.java:261-293
Timestamp: 2025-10-29T23:56:18.236Z
Learning: In NullAway's jdk-javac-plugin NullnessAnnotationSerializer, type variable bounds with annotations (e.g., `T extends Nullable Object`) are checked at their declaration sites by the typeParamHasAnnotation method for both class-level and method-level type parameters. The hasJSpecifyAnnotationDeep method is designed to check type uses (return types, parameters, etc.) and does not need a TYPEVAR case because type variable declaration bounds are already handled separately.
Applied to files:
nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java
🔇 Additional comments (4)
nullaway/src/test/java/com/uber/nullaway/CoreTests.java (2)
52-62: Align code indentation with the opening""".The code within this text block should be indented to align vertically with the opening
""", as requested by the maintainer. This same issue was flagged in a previous review.Likely an incorrect or invalid review comment.
63-92: Fix indentation alignment and internal formatting.The code within this text block should be indented to align vertically with the opening
""". Additionally, the internal indentation should be consistent. This same issue was flagged in a previous review.⛔ Skipped due to learnings
Learnt from: msridhar Repo: uber/NullAway PR: 1259 File: jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java:318-321 Timestamp: 2025-08-29T18:41:43.584Z Learning: Classes annotated with NullMarked are analyzed by NullAway even if they are not in packages specified by the AnnotatedPackages configuration. The NullMarked annotation guarantees NullAway analysis.Learnt from: msridhar Repo: uber/NullAway PR: 1245 File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102 Timestamp: 2025-08-14T18:50:06.159Z Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java (2)
33-54: Clean up indentation inconsistencies in the Shape_Stuff2.java text block.The code within this text block should be indented to align vertically with the opening
""". This same issue was flagged in a previous review.Likely an incorrect or invalid review comment.
139-170: Clean up indentation inconsistencies in the UnannotatedClass.java text block.The code within this text block should be indented to align vertically with the opening
""", and the internal indentation should be consistent. This same issue was flagged in a previous review.⛔ Skipped due to learnings
Learnt from: msridhar Repo: uber/NullAway PR: 1245 File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102 Timestamp: 2025-08-14T18:50:06.159Z Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.Learnt from: msridhar Repo: uber/NullAway PR: 1259 File: jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java:318-321 Timestamp: 2025-08-29T18:41:43.584Z Learning: Classes annotated with NullMarked are analyzed by NullAway even if they are not in packages specified by the AnnotatedPackages configuration. The NullMarked annotation guarantees NullAway analysis.
msridhar
left a comment
There was a problem hiding this comment.
LGTM! Note that this doesn't fully address #1425. That issue covers removing calls to addSourceFile everywhere in tests and replacing with addSourceLines. I checked and every @SuppressWarnings("deprecation") in NullAway code I think is due to this issue. @cobayo if you'd like to fix more of these in follow-up PRs that would be much appreciated!
|
Got it! I see that there are still many instances to be fixed. I'll work on them incrementally in my next PRs. Thanks for pointing that out! |
…deprecated addSourceFile Replaces all calls to deprecated CompilationTestHelper#addSourceFile with addSourceLines, inlining the source code as text blocks. This follows the same pattern as PR uber#1426 which handled CoreTests and UnannotatedTests. Changes: - ThriftTests: Replace 1 addSourceFile call (Util.java inlined) - Java8Tests: Replace 4 addSourceFile calls (NullAwayJava8PositiveCases, NullAwayJava8NegativeCases, NullAwaySuperFunctionalInterface, NullAwayOverrideFunctionalInterfaces all inlined) - Remove @SuppressWarnings("deprecation") annotations from both classes - Delete 4 now-unused testdata files for Java8Tests Fixes uber#1425 (partial - remaining test files can be addressed in follow-up PRs)
…deprecated addSourceFile (#1517) ## Summary Follow-up to #1426, continuing the migration from deprecated `CompilationTestHelper#addSourceFile` to `addSourceLines` as described in #1425. ## Changes **ThriftTests.java:** - Replace 1 `addSourceFile("testdata/Util.java")` call with `addSourceLines`, inlining the Util.java source as a text block - Remove `@SuppressWarnings("deprecation")` class annotation **Java8Tests.java:** - Replace 4 `addSourceFile` calls with `addSourceLines`: - `NullAwayJava8PositiveCases.java` (inlined) - `NullAwayJava8NegativeCases.java` (inlined) - `NullAwaySuperFunctionalInterface.java` (inlined) - `NullAwayOverrideFunctionalInterfaces.java` (inlined) - Remove `@SuppressWarnings("deprecation")` class and method annotations - Delete 4 now-unused testdata resource files ## Notes - Copyright/license headers are stripped when inlining (consistent with PR #1426 pattern) - `Util.java` resource file is **not** deleted — it is still referenced by `-XepOpt:NullAway:CastToNonNullMethod=com.uber.nullaway.testdata.Util.castToNonNull` in other test files - Remaining test files with `addSourceFile` calls (InitializationTests, AndroidTest, FrameworkTests, CoreTests) can be addressed in follow-up PRs to keep reviews manageable Fixes #1425 (partial) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Tests** * Modernized test infrastructure to reduce deprecation warnings and improve code organization. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Nanook <nanookclaw@users.noreply.github.com> Co-authored-by: Manu Sridharan <msridhar@gmail.com>
Refactor UnannotatedTests to inline multiple test data files
Description
Following the suggestion in #1425, this PR modernizes the test cases in
UnannotatedTests.javaby inlining external source files. This improves test maintainability and removes reliance on deprecatedaddSourceFilecalls.Changes
UnannotatedTests.javafromaddSourceFiletoaddSourceLines.testdatadirectory.@SuppressWarnings("deprecation")annotations.Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.