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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6ee802c
Add NullAway plugin.
maciejwalkowiak Apr 23, 2021
58f727a
Add nullability annotations for `App`, `Request`, `SentryId`.
maciejwalkowiak Apr 23, 2021
4810f24
Add nullability annotations for `Browser`, `Device`, `OperatingSystem`.
maciejwalkowiak Apr 23, 2021
bc25307
Refactor
maciejwalkowiak Apr 23, 2021
fed90f6
Fix tests.
maciejwalkowiak Apr 23, 2021
fff6e0d
Add nullability annotations for `Gpu`, `SentryRuntime`, `SentrySpan`.
maciejwalkowiak Apr 23, 2021
d41f15f
Add nullability annotations for `Message`, `SentryThread`.
maciejwalkowiak Apr 26, 2021
129cbab
Merge remote-tracking branch 'origin/main' into nullability
maciejwalkowiak Apr 28, 2021
106c3e1
Add nullability annotations for `DebugMeta`, `SdkInfo`, `SentryExcept…
maciejwalkowiak Apr 28, 2021
0411d37
Add nullability annotations for the rest of the protocol package.
maciejwalkowiak Apr 29, 2021
2cf4f90
Add nullability annotations to `transport` package.
maciejwalkowiak Apr 29, 2021
3c73221
Add nullability annotations to `util` package.
maciejwalkowiak Apr 29, 2021
5bc9b98
Add nullability annotations to `transport` package.
maciejwalkowiak Apr 30, 2021
37a1274
Add nullability annotations to `SentrySpan`
maciejwalkowiak Apr 30, 2021
f19c1c5
Add nullability annotations.
maciejwalkowiak Apr 30, 2021
69f707e
Add nullability annotations to `ISerializer`
maciejwalkowiak Apr 30, 2021
98f5049
Add nullability annotations.
maciejwalkowiak Apr 30, 2021
ef5dcde
Add nullability annotations to `adapters` package. (#1448)
maciejwalkowiak Apr 30, 2021
c4daf63
Add nullability annotations to `SentryEvent`, `SentryBaseEvent`.
maciejwalkowiak Apr 30, 2021
b042b91
Merge remote-tracking branch 'origin/nullability' into nullability-tr…
maciejwalkowiak Apr 30, 2021
65bdc22
Add nullability annotations.
maciejwalkowiak May 3, 2021
dee5772
Add nullability annotations to logger classes.
maciejwalkowiak May 3, 2021
69726a0
Add nullability annotations.
maciejwalkowiak May 3, 2021
d6fcfef
Add nullability annotations.
maciejwalkowiak May 3, 2021
9642217
Add nullability annotations to `SentryClient`
maciejwalkowiak May 3, 2021
90cba1a
Add nullability annotations.
maciejwalkowiak May 3, 2021
817e5b4
Polish tests.
maciejwalkowiak May 3, 2021
3c87b97
Handle `Scope#setTransaction` with `null`
maciejwalkowiak May 3, 2021
7aa2add
Polish.
maciejwalkowiak May 3, 2021
099dbab
Polish.
maciejwalkowiak May 3, 2021
57d0c74
Polish.
maciejwalkowiak May 5, 2021
66aa861
Update sentry/src/main/java/io/sentry/cache/EnvelopeCache.java
maciejwalkowiak May 7, 2021
246faf0
Fix logger nullability.
maciejwalkowiak May 7, 2021
a951170
Fix Scope#setTransaction nullability.
maciejwalkowiak May 7, 2021
2bfb639
Add explanation why NullAway is suppressed.
maciejwalkowiak May 7, 2021
71eca42
Polish.
maciejwalkowiak May 7, 2021
3da98b1
Drop InvalidDsnException.
maciejwalkowiak May 7, 2021
c764eb9
Polish.
maciejwalkowiak May 7, 2021
c5473c0
Polish `EnvelopeReader`.
maciejwalkowiak May 7, 2021
f64c188
Polish.
maciejwalkowiak May 7, 2021
744425c
Changelog.
maciejwalkowiak May 7, 2021
e1b1f7e
Merge remote-tracking branch 'origin/main' into nullability
maciejwalkowiak May 10, 2021
b577af5
release on Session is not null
maciejwalkowiak May 10, 2021
f05a251
Merge remote-tracking branch 'origin/main' into nullability
maciejwalkowiak May 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -30,6 +30,7 @@ Breaking Changes:
* Bump: sentry-native to 0.4.9 (#1431)
* Fix: Set Span status for OkHttp integration (#1447)
* Fix: Set user on transaction in Spring & Spring Boot integrations (#1443)
* Ref: nullability annotations to Sentry module (#1439)

# 4.4.0-alpha.2

Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/java/Config.kt
Expand Up @@ -102,6 +102,7 @@ object Config {
val mockitoInline = "org.mockito:mockito-inline:3.8.0"
val awaitility = "org.awaitility:awaitility-kotlin:4.0.3"
val mockWebserver = "com.squareup.okhttp3:mockwebserver:4.9.0"
val jsonUnit = "net.javacrumbs.json-unit:json-unit:2.11.1"
}

object QualityPlugins {
Expand Down Expand Up @@ -146,6 +147,7 @@ object Config {
val nopenChecker = "com.jakewharton.nopen:nopen-checker:$nopenVersion"
val errorprone = "com.google.errorprone:error_prone_core:2.5.1"
val errorProneJavac8 = "com.google.errorprone:javac:9+181-r4173-1"
val errorProneNullAway = "com.uber.nullaway:nullaway:0.9.1"
}

object NativePlugins {
Expand Down
Expand Up @@ -3,6 +3,7 @@
import android.util.Log;
import io.sentry.ILogger;
import io.sentry.SentryLevel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

final class AndroidLogger implements ILogger {
Expand All @@ -11,18 +12,28 @@ final class AndroidLogger implements ILogger {

@SuppressWarnings("AnnotateFormatMethod")
@Override
public void log(SentryLevel level, String message, Object... args) {
public void log(
final @NotNull SentryLevel level,
final @NotNull String message,
final @Nullable Object... args) {
Log.println(toLogcatLevel(level), tag, String.format(message, args));
}

@SuppressWarnings("AnnotateFormatMethod")
@Override
public void log(SentryLevel level, Throwable throwable, String message, Object... args) {
public void log(
final @NotNull SentryLevel level,
final @Nullable Throwable throwable,
final @NotNull String message,
final @Nullable Object... args) {
log(level, String.format(message, args), throwable);
}

@Override
public void log(SentryLevel level, String message, Throwable throwable) {
public void log(
final @NotNull SentryLevel level,
final @NotNull String message,
final @Nullable Throwable throwable) {

switch (level) {
case INFO:
Expand All @@ -49,7 +60,7 @@ public boolean isEnabled(@Nullable SentryLevel level) {
return true;
}

private int toLogcatLevel(SentryLevel sentryLevel) {
private int toLogcatLevel(final @NotNull SentryLevel sentryLevel) {
switch (sentryLevel) {
case INFO:
return Log.INFO;
Expand Down
Expand Up @@ -141,7 +141,9 @@ class AndroidOptionsInitializerTest {

AndroidOptionsInitializer.init(sentryOptions, mockContext)

assertTrue(sentryOptions.distinctId.isNotEmpty())
assertNotNull(sentryOptions.distinctId) {
assertTrue(it.isNotEmpty())
}

val installation = File(context.filesDir, Installation.INSTALLATION)
installation.deleteOnExit()
Expand Down
Expand Up @@ -105,8 +105,12 @@ class DefaultAndroidEventProcessorTest {

assertNotNull(sut.process(SentryEvent(), null)) {
assertNotNull(it.contexts.app)
assertEquals("test", it.debugMeta.images[0].uuid)
assertNotNull(it.dist)
assertNotNull(it.debugMeta) { debugMeta ->
assertNotNull(debugMeta.images) { images ->
assertEquals("test", images[0].uuid)
}
}
}
}

Expand All @@ -128,7 +132,11 @@ class DefaultAndroidEventProcessorTest {
}

assertNotNull(sut.process(event, null)) {
assertEquals("test", it.debugMeta.images[0].uuid)
assertNotNull(it.debugMeta) { debugMeta ->
assertNotNull(debugMeta.images) { images ->
assertEquals("test", images[0].uuid)
}
}
}
}

Expand All @@ -147,8 +155,12 @@ class DefaultAndroidEventProcessorTest {
}

assertNotNull(sut.process(event, null)) {
assertEquals("abc", it.debugMeta.images.first().uuid)
assertEquals("test", it.debugMeta.images.last().uuid)
assertNotNull(it.debugMeta) { debugMeta ->
assertNotNull(debugMeta.images) { images ->
assertEquals("abc", images.first().uuid)
assertEquals("test", images.last().uuid)
}
}
}
}

Expand All @@ -164,7 +176,9 @@ class DefaultAndroidEventProcessorTest {
}

assertNotNull(sut.process(event, null)) {
assertTrue(it.threads.first().isCurrent)
assertNotNull(it.threads) { threads ->
assertTrue(threads.first().isCurrent == true)
}
}
}

Expand All @@ -179,7 +193,9 @@ class DefaultAndroidEventProcessorTest {
}

assertNotNull(sut.process(event, null)) {
assertFalse(it.threads.first().isCurrent)
assertNotNull(it.threads) { threads ->
assertFalse(threads.first().isCurrent == true)
}
}
}

Expand Down
Expand Up @@ -6,7 +6,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.nhaarman.mockitokotlin2.mock
import io.sentry.ILogger
import io.sentry.Sentry
import io.sentry.exception.InvalidDsnException
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertFailsWith
Expand Down Expand Up @@ -93,7 +92,7 @@ class SentryInitProviderTest {

metaData.putString(ManifestMetadataReader.DSN, "invalid dsn")

assertFailsWith<InvalidDsnException> { sentryInitProvider.attachInfo(mockContext, providerInfo) }
assertFailsWith<IllegalArgumentException> { sentryInitProvider.attachInfo(mockContext, providerInfo) }
}

@Test
Expand Down
Expand Up @@ -12,6 +12,7 @@ import io.sentry.getExc
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
import timber.log.Timber
Expand Down Expand Up @@ -165,7 +166,9 @@ class SentryTimberTreeTest {
val sut = fixture.getSut()
sut.e("message")
verify(fixture.hub).captureEvent(check {
assertEquals("message", it.message.formatted)
assertNotNull(it.message) { message ->
assertEquals("message", message.formatted)
}
})
}

Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.util.TimeValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* {@link ITransport} implementation that executes request asynchronously in a non-blocking manner
Expand Down Expand Up @@ -62,7 +63,8 @@ public ApacheHttpClientTransport(

@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void send(SentryEnvelope envelope, Object hint) throws IOException {
public void send(final @NotNull SentryEnvelope envelope, final @Nullable Object hint)
throws IOException {
if (isSchedulingAllowed()) {
final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, hint);

Expand Down
Expand Up @@ -32,7 +32,7 @@ public ApacheHttpClientTransportFactory(final @NotNull TimeValue connectionTimeT
}

@Override
public ITransport create(
public @NotNull ITransport create(
final @NotNull SentryOptions options, final @NotNull RequestDetails requestDetails) {
Objects.requireNonNull(options, "options is required");
Objects.requireNonNull(requestDetails, "requestDetails is required");
Expand Down
52 changes: 31 additions & 21 deletions sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt
Expand Up @@ -81,9 +81,11 @@ class SentryHandlerTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals("testing message conversion 1, 2", event.message.formatted)
assertEquals("testing message conversion {0}, {1}", event.message.message)
assertEquals(listOf("1", "2"), event.message.params)
assertNotNull(event.message) { message ->
assertEquals("testing message conversion 1, 2", message.formatted)
assertEquals("testing message conversion {0}, {1}", message.message)
assertEquals(listOf("1", "2"), message.params)
}
assertEquals("jul.SentryHandlerTest", event.logger)
}, anyOrNull())
}
Expand All @@ -96,9 +98,11 @@ class SentryHandlerTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals("testing message conversion 1, 2", event.message.formatted)
assertEquals("testing message conversion {0}, {1}", event.message.message)
assertEquals(listOf("1", "2"), event.message.params)
assertNotNull(event.message) { message ->
assertEquals("testing message conversion 1, 2", message.formatted)
assertEquals("testing message conversion {0}, {1}", message.message)
assertEquals(listOf("1", "2"), message.params)
}
assertEquals("jul.SentryHandlerTest", event.logger)
}, anyOrNull())
}
Expand Down Expand Up @@ -206,16 +210,18 @@ class SentryHandlerTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals(2, event.breadcrumbs.size)
val breadcrumb = event.breadcrumbs[0]
val breadcrumbTime = Instant.ofEpochMilli(event.timestamp.time)
.atZone(ZoneId.of("UTC"))
.toLocalDateTime()
assertTrue { breadcrumbTime.plusSeconds(1).isAfter(utcTime) }
assertTrue { breadcrumbTime.minusSeconds(1).isBefore(utcTime) }
assertEquals("this should be a breadcrumb #1", breadcrumb.message)
assertEquals("jul.SentryHandlerTest", breadcrumb.category)
assertEquals(SentryLevel.DEBUG, breadcrumb.level)
assertNotNull(event.breadcrumbs) { breadcrumbs ->
assertEquals(2, breadcrumbs.size)
val breadcrumb = breadcrumbs[0]
val breadcrumbTime = Instant.ofEpochMilli(event.timestamp.time)
.atZone(ZoneId.of("UTC"))
.toLocalDateTime()
assertTrue { breadcrumbTime.plusSeconds(1).isAfter(utcTime) }
assertTrue { breadcrumbTime.minusSeconds(1).isBefore(utcTime) }
assertEquals("this should be a breadcrumb #1", breadcrumb.message)
assertEquals("jul.SentryHandlerTest", breadcrumb.category)
assertEquals(SentryLevel.DEBUG, breadcrumb.level)
}
}, anyOrNull())
}
}
Expand All @@ -230,8 +236,10 @@ class SentryHandlerTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals(1, event.breadcrumbs.size)
assertEquals("this should be a breadcrumb", event.breadcrumbs[0].message)
assertNotNull(event.breadcrumbs) { breadcrumbs ->
assertEquals(1, breadcrumbs.size)
assertEquals("this should be a breadcrumb", breadcrumbs[0].message)
}
}, anyOrNull())
}
}
Expand All @@ -247,9 +255,11 @@ class SentryHandlerTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals(2, event.breadcrumbs.size)
assertEquals("this should be a breadcrumb", event.breadcrumbs[0].message)
assertEquals("this should not be sent as the event but be a breadcrumb", event.breadcrumbs[1].message)
assertNotNull(event.breadcrumbs) { breadcrumbs ->
assertEquals(2, breadcrumbs.size)
assertEquals("this should be a breadcrumb", breadcrumbs[0].message)
assertEquals("this should not be sent as the event but be a breadcrumb", breadcrumbs[1].message)
}
}, anyOrNull())
}
}
Expand Down
Expand Up @@ -104,9 +104,11 @@ class SentryAppenderTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals("testing message conversion 1, 2", event.message.formatted)
assertEquals("testing message conversion {}, {}", event.message.message)
assertEquals(listOf("1", "2"), event.message.params)
assertNotNull(event.message) { message ->
assertEquals("testing message conversion 1, 2", message.formatted)
assertEquals("testing message conversion {}, {}", message.message)
assertEquals(listOf("1", "2"), message.params)
}
assertEquals("io.sentry.log4j2.SentryAppenderTest", event.logger)
}, anyOrNull())
}
Expand Down Expand Up @@ -303,16 +305,18 @@ class SentryAppenderTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals(2, event.breadcrumbs.size)
val breadcrumb = event.breadcrumbs[0]
val breadcrumbTime = Instant.ofEpochMilli(event.timestamp.time)
.atZone(fixture.utcTimeZone)
.toLocalDateTime()
assertTrue { breadcrumbTime.plusSeconds(1).isAfter(utcTime) }
assertTrue { breadcrumbTime.minusSeconds(1).isBefore(utcTime) }
assertEquals("this should be a breadcrumb #1", breadcrumb.message)
assertEquals("io.sentry.log4j2.SentryAppenderTest", breadcrumb.category)
assertEquals(SentryLevel.DEBUG, breadcrumb.level)
assertNotNull(event.breadcrumbs) { breadcrumbs ->
assertEquals(2, breadcrumbs.size)
val breadcrumb = breadcrumbs[0]
val breadcrumbTime = Instant.ofEpochMilli(event.timestamp.time)
.atZone(fixture.utcTimeZone)
.toLocalDateTime()
assertTrue { breadcrumbTime.plusSeconds(1).isAfter(utcTime) }
assertTrue { breadcrumbTime.minusSeconds(1).isBefore(utcTime) }
assertEquals("this should be a breadcrumb #1", breadcrumb.message)
assertEquals("io.sentry.log4j2.SentryAppenderTest", breadcrumb.category)
assertEquals(SentryLevel.DEBUG, breadcrumb.level)
}
}, anyOrNull())
}
}
Expand All @@ -327,8 +331,10 @@ class SentryAppenderTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals(1, event.breadcrumbs.size)
assertEquals("this should be a breadcrumb", event.breadcrumbs[0].message)
assertNotNull(event.breadcrumbs) { breadcrumbs ->
assertEquals(1, breadcrumbs.size)
assertEquals("this should be a breadcrumb", breadcrumbs[0].message)
}
}, anyOrNull())
}
}
Expand All @@ -344,9 +350,11 @@ class SentryAppenderTest {

await.untilAsserted {
verify(fixture.transport).send(checkEvent { event ->
assertEquals(2, event.breadcrumbs.size)
assertEquals("this should be a breadcrumb", event.breadcrumbs[0].message)
assertEquals("this should not be sent as the event but be a breadcrumb", event.breadcrumbs[1].message)
assertNotNull(event.breadcrumbs) { breadcrumbs ->
assertEquals(2, breadcrumbs.size)
assertEquals("this should be a breadcrumb", breadcrumbs[0].message)
assertEquals("this should not be sent as the event but be a breadcrumb", breadcrumbs[1].message)
}
}, anyOrNull())
}
}
Expand Down