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
./gradlew :spotlessApply
  • Loading branch information
Lucas committed Oct 30, 2024
commit 5f9ef0fbfbaafefa0d5fe40aafd0ec2b2e266c59
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ static void applyMetadata(
options.getSessionTrackingIntervalMillis()));

options.setMaxBreadcrumbs(
(int)readLong(
metadata,
logger,
MAX_BREADCRUMBS,
options.getMaxBreadcrumbs()));
(int) readLong(metadata, logger, MAX_BREADCRUMBS, options.getMaxBreadcrumbs()));

options.setEnableActivityLifecycleBreadcrumbs(
readBool(
Expand Down
43 changes: 29 additions & 14 deletions sentry/src/main/java/io/sentry/DisabledQueue.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package io.sentry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Queue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

final class DisabledQueue <E> extends AbstractCollection<E> implements Queue<E>, Serializable {
final class DisabledQueue<E> extends AbstractCollection<E> implements Queue<E>, Serializable {

/** Serialization version. */
private static final long serialVersionUID = -8423413834657610417L;

/** Constructor that creates a queue that does not accept any element. */
public DisabledQueue() { }
public DisabledQueue() {}

// -----------------------------------------------------------------------
/**
Expand All @@ -22,19 +23,23 @@ public DisabledQueue() { }
* @return this queue's size
*/
@Override
public int size() { return 0; }
public int size() {
return 0;
}

/**
* Returns true if this queue is empty; false otherwise.
*
* @return false
*/
@Override
public boolean isEmpty() { return false; }
public boolean isEmpty() {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

@lucas-zimerman @stefanosiano should this return true instead? If no, can we document why?

}

/** Does nothing. */
@Override
public void clear() { }
public void clear() {}

/**
* Since the queue is disabled, the element will not be added.
Expand All @@ -43,7 +48,9 @@ public void clear() { }
* @return false, always
*/
@Override
public boolean add(final @NotNull E element) { return false; }
public boolean add(final @NotNull E element) {
return false;
}

// -----------------------------------------------------------------------

Expand All @@ -59,16 +66,24 @@ public boolean offer(@NotNull E element) {
}

@Override
public @Nullable E poll() { return null; }
public @Nullable E poll() {
return null;
}

@Override
public @Nullable E element() { return null; }
public @Nullable E element() {
return null;
}

@Override
public @Nullable E peek() { return null; }
public @Nullable E peek() {
return null;
}

@Override
public @NotNull E remove() { throw new NoSuchElementException("queue is disabled"); }
public @NotNull E remove() {
throw new NoSuchElementException("queue is disabled");
}

// -----------------------------------------------------------------------

Expand All @@ -93,8 +108,8 @@ public E next() {

@Override
public void remove() {
throw new IllegalStateException();
}
throw new IllegalStateException();
}
};
}
}
6 changes: 3 additions & 3 deletions sentry/src/main/java/io/sentry/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,9 @@ public void clearAttachments() {
* @return the breadcrumbs queue
*/
private @NotNull Queue<Breadcrumb> createBreadcrumbsList(final int maxBreadcrumb) {
return maxBreadcrumb > 0 ?
SynchronizedQueue.synchronizedQueue(new CircularFifoQueue<>(maxBreadcrumb)) :
SynchronizedQueue.synchronizedQueue(new DisabledQueue<>());
return maxBreadcrumb > 0
? SynchronizedQueue.synchronizedQueue(new CircularFifoQueue<>(maxBreadcrumb))
: SynchronizedQueue.synchronizedQueue(new DisabledQueue<>());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions sentry/src/test/java/io/sentry/DisabledQueueTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DisabledQueueTest {
@Test
fun `isEmpty always returns false if add function was called`() {
val queue = DisabledQueue<Int>()
queue.add(1);
queue.add(1)

assertFalse(queue.isEmpty(), "isEmpty should always return false.")
}
Expand All @@ -45,14 +45,14 @@ class DisabledQueueTest {
@Test
fun `poll returns null`() {
val queue = DisabledQueue<Int>()
queue.add(1);
queue.add(1)
assertNull(queue.poll(), "poll should always return null.")
}

@Test
fun `peek returns null`() {
val queue = DisabledQueue<Int>()
queue.add(1);
queue.add(1)

assertNull(queue.peek(), "peek should always return null.")
}
Expand Down
Loading