Skip to content

Commit d2eb2ff

Browse files
committed
Remove use of java.util.Objects as is not available in android sdk versions lower than 19
1 parent c05e979 commit d2eb2ff

5 files changed

Lines changed: 106 additions & 39 deletions

File tree

rollbar-api/src/main/java/com/rollbar/api/payload/data/Data.java

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.rollbar.api.payload.data.body.Body;
55
import java.util.HashMap;
66
import java.util.Map;
7-
import java.util.Objects;
87

98
/**
109
* Represents the actual data being posted to Rollbar.
@@ -313,34 +312,88 @@ public boolean equals(Object o) {
313312
if (o == null || getClass() != o.getClass()) {
314313
return false;
315314
}
315+
316316
Data data = (Data) o;
317-
return Objects.equals(environment, data.environment)
318-
&& Objects.equals(body, data.body)
319-
&& level == data.level
320-
&& Objects.equals(timestamp, data.timestamp)
321-
&& Objects.equals(codeVersion, data.codeVersion)
322-
&& Objects.equals(platform, data.platform)
323-
&& Objects.equals(language, data.language)
324-
&& Objects.equals(framework, data.framework)
325-
&& Objects.equals(context, data.context)
326-
&& Objects.equals(request, data.request)
327-
&& Objects.equals(person, data.person)
328-
&& Objects.equals(server, data.server)
329-
&& Objects.equals(client, data.client)
330-
&& Objects.equals(custom, data.custom)
331-
&& Objects.equals(fingerprint, data.fingerprint)
332-
&& Objects.equals(title, data.title)
333-
&& Objects.equals(uuid, data.uuid)
334-
&& isUncaught == data.isUncaught
335-
&& Objects.equals(notifier, data.notifier);
317+
318+
if (isUncaught != data.isUncaught) {
319+
return false;
320+
}
321+
if (environment != null ? !environment.equals(data.environment) : data.environment != null) {
322+
return false;
323+
}
324+
if (body != null ? !body.equals(data.body) : data.body != null) {
325+
return false;
326+
}
327+
if (level != data.level) {
328+
return false;
329+
}
330+
if (timestamp != null ? !timestamp.equals(data.timestamp) : data.timestamp != null) {
331+
return false;
332+
}
333+
if (codeVersion != null ? !codeVersion.equals(data.codeVersion) : data.codeVersion != null) {
334+
return false;
335+
}
336+
if (platform != null ? !platform.equals(data.platform) : data.platform != null) {
337+
return false;
338+
}
339+
if (language != null ? !language.equals(data.language) : data.language != null) {
340+
return false;
341+
}
342+
if (framework != null ? !framework.equals(data.framework) : data.framework != null) {
343+
return false;
344+
}
345+
if (context != null ? !context.equals(data.context) : data.context != null) {
346+
return false;
347+
}
348+
if (request != null ? !request.equals(data.request) : data.request != null) {
349+
return false;
350+
}
351+
if (person != null ? !person.equals(data.person) : data.person != null) {
352+
return false;
353+
}
354+
if (server != null ? !server.equals(data.server) : data.server != null) {
355+
return false;
356+
}
357+
if (client != null ? !client.equals(data.client) : data.client != null) {
358+
return false;
359+
}
360+
if (custom != null ? !custom.equals(data.custom) : data.custom != null) {
361+
return false;
362+
}
363+
if (fingerprint != null ? !fingerprint.equals(data.fingerprint) : data.fingerprint != null) {
364+
return false;
365+
}
366+
if (title != null ? !title.equals(data.title) : data.title != null) {
367+
return false;
368+
}
369+
if (uuid != null ? !uuid.equals(data.uuid) : data.uuid != null) {
370+
return false;
371+
}
372+
return notifier != null ? notifier.equals(data.notifier) : data.notifier == null;
336373
}
337374

338375
@Override
339376
public int hashCode() {
340-
return Objects
341-
.hash(environment, body, level, timestamp, codeVersion, platform, language, framework,
342-
context, request, person, server, client, custom, fingerprint, title, uuid, isUncaught,
343-
notifier);
377+
int result = environment != null ? environment.hashCode() : 0;
378+
result = 31 * result + (body != null ? body.hashCode() : 0);
379+
result = 31 * result + (level != null ? level.hashCode() : 0);
380+
result = 31 * result + (timestamp != null ? timestamp.hashCode() : 0);
381+
result = 31 * result + (codeVersion != null ? codeVersion.hashCode() : 0);
382+
result = 31 * result + (platform != null ? platform.hashCode() : 0);
383+
result = 31 * result + (language != null ? language.hashCode() : 0);
384+
result = 31 * result + (framework != null ? framework.hashCode() : 0);
385+
result = 31 * result + (context != null ? context.hashCode() : 0);
386+
result = 31 * result + (request != null ? request.hashCode() : 0);
387+
result = 31 * result + (person != null ? person.hashCode() : 0);
388+
result = 31 * result + (server != null ? server.hashCode() : 0);
389+
result = 31 * result + (client != null ? client.hashCode() : 0);
390+
result = 31 * result + (custom != null ? custom.hashCode() : 0);
391+
result = 31 * result + (fingerprint != null ? fingerprint.hashCode() : 0);
392+
result = 31 * result + (title != null ? title.hashCode() : 0);
393+
result = 31 * result + (uuid != null ? uuid.hashCode() : 0);
394+
result = 31 * result + (isUncaught ? 1 : 0);
395+
result = 31 * result + (notifier != null ? notifier.hashCode() : 0);
396+
return result;
344397
}
345398

346399
@Override

rollbar-api/src/main/java/com/rollbar/api/payload/data/body/CrashReport.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.rollbar.api.json.JsonSerializable;
44
import java.util.HashMap;
55
import java.util.Map;
6-
import java.util.Objects;
76

87
/**
98
* Represents a crash report (currently only for iOS, eventually Android, and maybe (if possible)
@@ -49,8 +48,10 @@ public boolean equals(Object o) {
4948
if (o == null || getClass() != o.getClass()) {
5049
return false;
5150
}
51+
5252
CrashReport that = (CrashReport) o;
53-
return Objects.equals(raw, that.raw);
53+
54+
return raw != null ? raw.equals(that.raw) : that.raw == null;
5455
}
5556

5657
@Override

rollbar-api/src/main/java/com/rollbar/api/payload/data/body/Message.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.rollbar.api.json.JsonSerializable;
66
import java.util.HashMap;
77
import java.util.Map;
8-
import java.util.Objects;
98

109
/**
1110
* Represents a message (text) sent to Rollbar, possible with additional information.
@@ -60,16 +59,18 @@ public boolean equals(Object o) {
6059
if (o == null || getClass() != o.getClass()) {
6160
return false;
6261
}
62+
6363
Message message = (Message) o;
64-
if (body != null ? !Objects.equals(body, message.body) : message.body != null) {
64+
65+
if (body != null ? !body.equals(message.body) : message.body != null) {
6566
return false;
6667
}
6768
return metadata != null ? metadata.equals(message.metadata) : message.metadata == null;
6869
}
6970

7071
@Override
7172
public int hashCode() {
72-
int result = body != null ? Objects.hash(body) : 0;
73+
int result = body != null ? body.hashCode() : 0;
7374
result = 31 * result + (metadata != null ? metadata.hashCode() : 0);
7475
return result;
7576
}

rollbar-java/src/main/java/com/rollbar/notifier/Rollbar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import com.rollbar.notifier.config.ConfigProvider;
99
import com.rollbar.notifier.uncaughtexception.RollbarUncaughtExceptionHandler;
1010
import com.rollbar.notifier.util.BodyFactory;
11+
import com.rollbar.notifier.util.ObjectsUtils;
1112
import com.rollbar.notifier.wrapper.RollbarThrowableWrapper;
1213
import com.rollbar.notifier.wrapper.ThrowableWrapper;
1314
import java.lang.Thread.UncaughtExceptionHandler;
1415
import java.util.HashMap;
1516
import java.util.Map;
16-
import java.util.Objects;
1717
import java.util.concurrent.locks.Lock;
1818
import java.util.concurrent.locks.ReadWriteLock;
1919
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -88,7 +88,7 @@ public void handleUncaughtErrors() {
8888
* @param thread the thread to handle errors on.
8989
*/
9090
public void handleUncaughtErrors(Thread thread) {
91-
Objects.requireNonNull(thread, "thread");
91+
ObjectsUtils.requireNonNull(thread, "thread");
9292
LOGGER.debug("Handling uncaught errors for thread: {}.", thread);
9393
UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
9494
thread.setUncaughtExceptionHandler(new RollbarUncaughtExceptionHandler(this,

rollbar-java/src/main/java/com/rollbar/notifier/wrapper/RollbarThrowableWrapper.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.rollbar.notifier.wrapper;
22

33
import java.util.Arrays;
4-
import java.util.Objects;
54

65
/**
76
* Implementation of the {@link ThrowableWrapper throwable wrapper}.
@@ -96,19 +95,32 @@ public boolean equals(Object o) {
9695
if (o == null || getClass() != o.getClass()) {
9796
return false;
9897
}
98+
9999
RollbarThrowableWrapper that = (RollbarThrowableWrapper) o;
100-
return Objects.equals(className, that.className)
101-
&& Objects.equals(message, that.message)
102-
&& Arrays.equals(stackTraceElements, that.stackTraceElements)
103-
&& Objects.equals(cause, that.cause)
104-
&& Objects.equals(throwable, that.throwable);
100+
101+
if (className != null ? !className.equals(that.className) : that.className != null) {
102+
return false;
103+
}
104+
if (message != null ? !message.equals(that.message) : that.message != null) {
105+
return false;
106+
}
107+
// Probably incorrect - comparing Object[] arrays with Arrays.equals
108+
if (!Arrays.equals(stackTraceElements, that.stackTraceElements)) {
109+
return false;
110+
}
111+
if (cause != null ? !cause.equals(that.cause) : that.cause != null) {
112+
return false;
113+
}
114+
return throwable != null ? throwable.equals(that.throwable) : that.throwable == null;
105115
}
106116

107117
@Override
108118
public int hashCode() {
109-
110-
int result = Objects.hash(className, message, cause, throwable);
119+
int result = className != null ? className.hashCode() : 0;
120+
result = 31 * result + (message != null ? message.hashCode() : 0);
111121
result = 31 * result + Arrays.hashCode(stackTraceElements);
122+
result = 31 * result + (cause != null ? cause.hashCode() : 0);
123+
result = 31 * result + (throwable != null ? throwable.hashCode() : 0);
112124
return result;
113125
}
114126
}

0 commit comments

Comments
 (0)