Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add finals
  • Loading branch information
romtsn committed Feb 22, 2024
commit 86baf7fc968a8ccc7dc7e8bdce22bd37e60bf8a6
3 changes: 2 additions & 1 deletion sentry/src/main/java/io/sentry/ObjectReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import org.jetbrains.annotations.Nullable;

public interface ObjectReader extends Closeable {
static @Nullable Date dateOrNull(@Nullable String dateString, final @NotNull ILogger logger) {
static @Nullable Date dateOrNull(
final @Nullable String dateString, final @NotNull ILogger logger) {
if (dateString == null) {
return null;
}
Expand Down
53 changes: 27 additions & 26 deletions sentry/src/main/java/io/sentry/util/MapObjectReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public MapObjectReader(final Map<String, Object> root) {
}

@Override
public void nextUnknown(final @NotNull ILogger logger, Map<String, Object> unknown, String name) {
public void nextUnknown(
final @NotNull ILogger logger, final Map<String, Object> unknown, final String name) {
try {
unknown.put(name, nextObjectOrNull());
} catch (Exception exception) {
Expand Down Expand Up @@ -63,14 +64,14 @@ public <T> T nextOrNull(
@Nullable
@Override
public Date nextDateOrNull(final @NotNull ILogger logger) throws IOException {
String dateString = nextStringOrNull();
final String dateString = nextStringOrNull();
return ObjectReader.dateOrNull(dateString, logger);
}

@Nullable
@Override
public TimeZone nextTimeZoneOrNull(final @NotNull ILogger logger) throws IOException {
String timeZoneId = nextStringOrNull();
final String timeZoneId = nextStringOrNull();
return timeZoneId != null ? TimeZone.getTimeZone(timeZoneId) : null;
}

Expand All @@ -87,7 +88,7 @@ public JsonToken peek() throws IOException {
return JsonToken.END_DOCUMENT;
}

Map.Entry<String, Object> currentEntry = stack.peekLast();
final Map.Entry<String, Object> currentEntry = stack.peekLast();
if (currentEntry == null) {
return JsonToken.END_DOCUMENT;
}
Expand All @@ -96,7 +97,7 @@ public JsonToken peek() throws IOException {
return JsonToken.NAME;
}

Object value = currentEntry.getValue();
final Object value = currentEntry.getValue();

if (value instanceof Map) {
return JsonToken.BEGIN_OBJECT;
Expand All @@ -118,7 +119,7 @@ public JsonToken peek() throws IOException {
@NotNull
@Override
public String nextName() throws IOException {
Map.Entry<String, Object> currentEntry = stack.peekLast();
final Map.Entry<String, Object> currentEntry = stack.peekLast();
if (currentEntry != null && currentEntry.getKey() != null) {
return currentEntry.getKey();
}
Expand All @@ -127,11 +128,11 @@ public String nextName() throws IOException {

@Override
public void beginObject() throws IOException {
Map.Entry<String, Object> currentEntry = stack.removeLast();
final Map.Entry<String, Object> currentEntry = stack.removeLast();
if (currentEntry == null) {
throw new IOException("No more entries");
}
Object value = currentEntry.getValue();
final Object value = currentEntry.getValue();
if (value instanceof Map) {
// insert a dummy entry to indicate end of an object
stack.addLast(new AbstractMap.SimpleEntry<>(null, JsonToken.END_OBJECT));
Expand All @@ -153,17 +154,17 @@ public void endObject() throws IOException {

@Override
public void beginArray() throws IOException {
Map.Entry<String, Object> currentEntry = stack.removeLast();
final Map.Entry<String, Object> currentEntry = stack.removeLast();
if (currentEntry == null) {
throw new IOException("No more entries");
}
Object value = currentEntry.getValue();
final Object value = currentEntry.getValue();
if (value instanceof List) {
// insert a dummy entry to indicate end of an object
stack.addLast(new AbstractMap.SimpleEntry<>(null, JsonToken.END_ARRAY));
// extract map entries onto the stack
for (int i = ((List<?>) value).size() - 1; i >= 0; i--) {
Object entry = ((List<?>) value).get(i);
final Object entry = ((List<?>) value).get(i);
stack.addLast(new AbstractMap.SimpleEntry<>(null, entry));
}
} else {
Expand All @@ -185,7 +186,7 @@ public boolean hasNext() throws IOException {

@Override
public int nextInt() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value instanceof Number) {
return ((Number) value).intValue();
} else {
Expand All @@ -196,7 +197,7 @@ public int nextInt() throws IOException {
@Nullable
@Override
public Integer nextIntegerOrNull() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value instanceof Number) {
return ((Number) value).intValue();
}
Expand All @@ -205,7 +206,7 @@ public Integer nextIntegerOrNull() throws IOException {

@Override
public long nextLong() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value instanceof Number) {
return ((Number) value).longValue();
} else {
Expand All @@ -216,7 +217,7 @@ public long nextLong() throws IOException {
@Nullable
@Override
public Long nextLongOrNull() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value instanceof Number) {
return ((Number) value).longValue();
}
Expand All @@ -225,7 +226,7 @@ public Long nextLongOrNull() throws IOException {

@Override
public String nextString() throws IOException {
String value = nextValueOrNull();
final String value = nextValueOrNull();
if (value != null) {
return value;
} else {
Expand All @@ -241,7 +242,7 @@ public String nextStringOrNull() throws IOException {

@Override
public boolean nextBoolean() throws IOException {
Boolean value = nextValueOrNull();
final Boolean value = nextValueOrNull();
if (value != null) {
return value;
} else {
Expand All @@ -257,7 +258,7 @@ public Boolean nextBooleanOrNull() throws IOException {

@Override
public double nextDouble() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value instanceof Number) {
return ((Number) value).doubleValue();
} else {
Expand All @@ -268,7 +269,7 @@ public double nextDouble() throws IOException {
@Nullable
@Override
public Double nextDoubleOrNull() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value instanceof Number) {
return ((Number) value).doubleValue();
}
Expand All @@ -278,7 +279,7 @@ public Double nextDoubleOrNull() throws IOException {
@Nullable
@Override
public Float nextFloatOrNull() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value instanceof Number) {
return ((Number) value).floatValue();
}
Expand All @@ -287,7 +288,7 @@ public Float nextFloatOrNull() throws IOException {

@Override
public float nextFloat() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value instanceof Number) {
return ((Number) value).floatValue();
} else {
Expand All @@ -297,14 +298,14 @@ public float nextFloat() throws IOException {

@Override
public void nextNull() throws IOException {
Object value = nextValueOrNull();
final Object value = nextValueOrNull();
if (value != null) {
throw new IOException("Expected null but was " + peek());
}
}

@Override
public void setLenient(boolean lenient) {}
public void setLenient(final boolean lenient) {}

@Override
public void skipValue() throws IOException {}
Expand All @@ -324,17 +325,17 @@ private <T> T nextValueOrNull() throws IOException {
private <T> T nextValueOrNull(
final @Nullable ILogger logger, final @Nullable JsonDeserializer<T> deserializer)
throws Exception {
Map.Entry<String, Object> currentEntry = stack.peekLast();
final Map.Entry<String, Object> currentEntry = stack.peekLast();
if (currentEntry == null) {
return null;
}
T value = (T) currentEntry.getValue();
final T value = (T) currentEntry.getValue();
if (deserializer != null && logger != null) {
return deserializer.deserialize(this, logger);
} else if (value instanceof List) {
List<Object> list = new ArrayList<>((List<Object>) value);
if (!list.isEmpty()) {
T next = (T) list.remove(0);
final T next = (T) list.remove(0);
if (next instanceof Map) {
stack.addLast(new AbstractMap.SimpleEntry<>(null, next));
}
Expand Down