Skip to content
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

Add nullability annotations to sentry module. #1439

Merged
merged 44 commits into from
May 10, 2021
Merged

Add nullability annotations to sentry module. #1439

merged 44 commits into from
May 10, 2021

Conversation

maciejwalkowiak
Copy link
Contributor

@maciejwalkowiak maciejwalkowiak commented Apr 23, 2021

📜 Description

Adds @Nullable & @NotNull annotations to classes and interfaces in sentry module.

💡 Motivation and Context

Better Kotlin interoperatibility and cleaner API.

💚 How did you test it?

With NullAway Errorprone plugin.

I did not unfortunately find a way to ensure that API is 100% documented. Errorprone triggers violation if the null safety is violated in the code, but if the code is not used, it won't trigger an error.

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

Breaking changes affect mainly Kotlin users.

🔮 Next steps

Add nullability annotations to other modules - as PRs to nullability branch.

@bruno-garcia
Copy link
Member

Excited about this change!

@codecov-commenter
Copy link

codecov-commenter commented Apr 30, 2021

Codecov Report

Merging #1439 (3da98b1) into main (dd652c2) will decrease coverage by 0.26%.
The diff coverage is 47.54%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1439      +/-   ##
============================================
- Coverage     75.87%   75.61%   -0.27%     
- Complexity     1901     1905       +4     
============================================
  Files           189      189              
  Lines          6499     6532      +33     
  Branches        640      659      +19     
============================================
+ Hits           4931     4939       +8     
- Misses         1272     1277       +5     
- Partials        296      316      +20     
Impacted Files Coverage Δ Complexity Δ
...ry/transport/apache/ApacheHttpClientTransport.java 68.91% <ø> (ø) 10.00 <0.00> (ø)
...sport/apache/ApacheHttpClientTransportFactory.java 100.00% <ø> (ø) 3.00 <0.00> (ø)
...try/src/main/java/io/sentry/CircularFifoQueue.java 34.95% <ø> (ø) 17.00 <0.00> (ø)
...src/main/java/io/sentry/CustomSamplingContext.java 25.00% <ø> (ø) 1.00 <0.00> (ø)
...ntry/src/main/java/io/sentry/DiagnosticLogger.java 94.44% <ø> (ø) 14.00 <0.00> (ø)
sentry/src/main/java/io/sentry/EnvelopeReader.java 88.05% <0.00%> (-4.13%) 17.00 <0.00> (ø)
sentry/src/main/java/io/sentry/GsonSerializer.java 100.00% <ø> (ø) 10.00 <0.00> (ø)
sentry/src/main/java/io/sentry/HubAdapter.java 5.26% <ø> (ø) 3.00 <0.00> (ø)
sentry/src/main/java/io/sentry/IHub.java 95.00% <ø> (+10.00%) 14.00 <0.00> (+1.00)
sentry/src/main/java/io/sentry/ISentryClient.java 89.47% <ø> (ø) 10.00 <0.00> (ø)
... and 91 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd652c2...3da98b1. Read the comment docs.

@maciejwalkowiak
Copy link
Contributor Author

@marandaneto have a look please. Since this is a breaking change anyway, perhaps we can re-evaluate if some parameters should/should not be nullable

@@ -191,11 +191,10 @@ private void setThreads(final @NotNull SentryEvent event) {
// crashed properly
List<Long> mechanismThreadIds = null;

final boolean hasExceptions =
event.getExceptions() != null && !event.getExceptions().isEmpty();
final List<SentryException> eventExceptions = event.getExceptions();
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering why we've changed the hasExceptions instead of checking NPE and emptiness 2 times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NullAway is not able to recognize this check. If we want to keep using it, we would either have to do it as in PR, or disable warning for this method.

@@ -26,7 +26,7 @@ public SendFireAndForgetEnvelopeSender(
Objects.requireNonNull(options, "SentryOptions is required");

final String dirPath = sendFireAndForgetDirPath.getDirPath();
if (!hasValidPath(dirPath, options.getLogger())) {
if (dirPath == null || !hasValidPath(dirPath, options.getLogger())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

hasValidPath already checks for NPE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same reason as here #1439 (comment)

@@ -26,7 +26,7 @@ public SendFireAndForgetOutboxSender(
Objects.requireNonNull(options, "SentryOptions is required");

final String dirPath = sendFireAndForgetDirPath.getDirPath();
if (!hasValidPath(dirPath, options.getLogger())) {
if (dirPath == null || !hasValidPath(dirPath, options.getLogger())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same reason as here #1439 (comment)

@marandaneto
Copy link
Contributor

marandaneto commented May 7, 2021

  • missing changelog.
  • there are a few methods missing a return nullability annotation.
  • there are a few changes that actually may introduce new behaviors, they are not covered by unit tests
  • major chunk of work is done, well done

@maciejwalkowiak
Copy link
Contributor Author

Few comments left to resolve and take decision. The rest is fixed.

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

I left my last notes over the open issues. Nothing major so I'm OK either way.
Since this is huge I'm just hoping we merge so:

:shipit: :shipit:

😄

@maciejwalkowiak
Copy link
Contributor Author

Session#release changed back to @NotNull.

@bruno-garcia
Copy link
Member

Merging this to move things! Looks like nothing major pending, but lets work on follow up PRs if something comes up

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.

4 participants