Conversation
JSpecify is de-facto standard annotations for marking nullability of variables, parameters, return values and fields. Supported by all IDEs. 1. By default, we mark everything as non-nullable (see @NullMarked in package-info.java) 2. When needed, we mark the nullable parameters/fields as @nullable.
|
Awesome! Just wondering, could this start breaking things for libraries which depend on us, or Kotlin projects? Just wonder if we release this, should this be 2.x release or 3.x ? |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1764 +/- ##
============================================
+ Coverage 92.43% 92.55% +0.11%
Complexity 3450 3450
============================================
Files 339 339
Lines 6794 6794
Branches 670 663 -7
============================================
+ Hits 6280 6288 +8
+ Misses 351 348 -3
+ Partials 163 158 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
No, it doesn't need to be 3.0 |
|
Okay. My understanding was that before the code is annotated, Kotlin will treat this as platform types. So, the following code would work: Both would work. But if I look here: https://resources.jetbrains.com/storage/products/kotlinconf-2025/may-23/JSpecify_%20Java%20Nullness%20Annotations%20and%20Kotlin%20_%20David%20Baker.pdf, they say:
So, if we'd add @nullable to something Kotlin clients assumed was non-null, they'll get compile errors if they're using it in a non-null context without null checks. So, something like this might break Kotlin consumers, I think: Also, I think the code is perhaps incorrect, I don't think it should ever return a nullable userId. (and yes, I know what the documentation says, but it's also a bit sus) Wdyt? |
@bodiam Hm... Yes, that's right: the new annotations can break compilation of existing Kotlin code. val userId1: String = faker.credentials().userId(null);
So yes, we need to release it as DataFaker 3.0.0 :) P.S. And yes, good point: method |
method `faker.credentials.userId()` never returns null.
kingthorin
left a comment
There was a problem hiding this comment.
It's kind of a lot to review, especially with the unrelated typo fixes etc.
These are the only things I noticed.
src/main/java/net/datafaker/internal/helper/SingletonLocale.java
Outdated
Show resolved
Hide resolved
|
is there any enforcer that could fail the build if missed? |
Just to be clear on this: I do really like the PR, I think we should absolutely do it, just may need a bit of checking on the impact, and how we're communicating this, that's all. I have no issue with releasing DF 3.x either. |
|
@asolntsev can you explain how you put annotations? |
|
I used Claude Code to review it as well: SummaryThis branch introduces JSpecify (@NullMarked, @nullable) and Error Prone (@CheckReturnValue) annotations across the entire codebase. It adds package-info.java files to 22 packages, making non-null the default for FindingsCriticalNone found. Improvements
Nitpicks
ConclusionApproved. This is a high-quality, thorough nullability annotation pass. The @NullMarked + @nullable approach with JSpecify is the modern best practice for Java, the provided scope is correct, and the various code The only item I'd suggest addressing before merge is the stale Javadoc on Credentials.userId() (finding #2). |
As I explained in the PR description:
So I added @nullable in places where i see that null is actually expected. Of course, I might make a mistake in some of these places (but I hope very few). |
1e89896 to
2618d93
Compare
2618d93 to
59c3050
Compare
Yes, there is library "NullAway" (probably some others as well). |
…d()` without regex parameter
|
I don't feel like my skills/knowledge give me a good place from which to review this PR. As a contributor how would I know when/if I should be annotating something? |
Yes, unfortunately, such PR is hard to review.
Looks massive, but actually simple. |
|
Seems reasonable to me |
JSpecify is de-facto standard annotations for marking nullability of variables, parameters, return values and fields. Supported by all IDEs.
All remarkable libraries have migrated to JSpecify: Spring, JUnit etc.