Fixed - synthetic class shouldn't be allowed to be used as a comparator for RPriorityQueue objects. #3908

pull/6406/head
Nikita Koksharov 2 weeks ago
parent c1d8c4f84b
commit 823317681e

@ -340,6 +340,10 @@ public class RedissonPriorityQueue<V> extends BaseRedissonList<V> implements RPr
@Override
public boolean trySetComparator(Comparator<? super V> comparator) {
if (comparator.getClass().isSynthetic()) {
throw new IllegalArgumentException("Synthetic classes aren't allowed");
}
String className = comparator.getClass().getName();
String comparatorSign = className + ":" + calcClassSign(className);

@ -5,12 +5,15 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RFuture;
import org.redisson.api.RPriorityBlockingQueue;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.misc.RedisURI;
import org.testcontainers.containers.GenericContainer;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -20,6 +23,14 @@ import static org.assertj.core.api.Assertions.assertThat;
public class RedissonPriorityBlockingQueueTest extends RedissonBlockingQueueTest {
@Test
public void testLambda() {
RPriorityBlockingQueue<RedisURI> priorityQueue = redisson.getPriorityBlockingQueue("anyQueue");
Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> {
priorityQueue.trySetComparator(Comparator.comparing(RedisURI::getHost));
});
}
@Test
public void testTakeInterrupted() throws InterruptedException {
AtomicBoolean interrupted = new AtomicBoolean();

Loading…
Cancel
Save