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

added requireNonNull utils #810

Merged
merged 3 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sentry/src/main/java/io/sentry/SentryClientFactory.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.sentry;

import static java.util.Objects.requireNonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import io.sentry.config.Lookup;
import io.sentry.dsn.Dsn;
import io.sentry.util.Nullable;
import io.sentry.util.Objects;
import io.sentry.util.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Factory in charge of creating {@link SentryClient} instances. The implementations should have a constructor with a
Expand All @@ -32,7 +32,7 @@ public abstract class SentryClientFactory {
* @param lookup the lookup to use
*/
protected SentryClientFactory(Lookup lookup) {
this.lookup = requireNonNull(lookup);
this.lookup = Objects.requireNonNull(lookup);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.sentry;

import static java.util.Objects.requireNonNull;

import io.sentry.config.Lookup;
import io.sentry.config.ResourceLoader;
import io.sentry.dsn.Dsn;
import io.sentry.util.Nullable;
import io.sentry.util.Objects;
import io.sentry.util.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -39,7 +38,7 @@ public final class SentryOptions {
* @throws NullPointerException if lookup is null
*/
public SentryOptions(Lookup lookup, @Nullable String dsn, @Nullable SentryClientFactory sentryClientFactory) {
this.lookup = requireNonNull(lookup, "lookup");
this.lookup = Objects.requireNonNull(lookup, "lookup");
this.dsn = resolveDsn(lookup, dsn);
this.sentryClientFactory = sentryClientFactory == null
? SentryClientFactory.instantiateFrom(this.lookup, this.dsn)
Expand Down Expand Up @@ -164,7 +163,7 @@ public Lookup getLookup() {
* @param lookup the lookup to use
*/
public void setLookup(Lookup lookup) {
this.lookup = requireNonNull(lookup);
this.lookup = Objects.requireNonNull(lookup);
}

/**
Expand Down
37 changes: 37 additions & 0 deletions sentry/src/main/java/io/sentry/util/Objects.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.sentry.util;

/**
* backport of Objects Utils which is not available on Android yet.
*/
public final class Objects {
private Objects() {

}

/**
* backport of Objects.requireNonNull which is not available on Android yet.
* @param obj object to NPE check
* @param message custom message for NullPointerException
* @param <T> obj type
* @return returns obj itself if it's not null
*/
public static <T> T requireNonNull(T obj, String message) {
if (obj == null) {
throw new NullPointerException(message);
}
return obj;
}

/**
* backport of Objects.requireNonNull which is not available on Android yet.
* @param obj object to NPE check
* @param <T> obj type
* @return returns obj itself if it's not null
*/
public static <T> T requireNonNull(T obj) {
if (obj == null) {
throw new NullPointerException();
}
return obj;
}
}