【JAVA】java.util.ArrayList cannot be cast to class java.lang.String

一、问题描述

21-05-25 14:39:34.110 ERROR [taskScheduler-12] o.s.s.s.TaskUtils$LoggingErrorHandler   :95  - Unexpected error occurred in scheduled task
java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.String (java.util.ArrayList and java.lang.String are in module java.base of loader 'bootstrap')
	at org.springframework.data.redis.serializer.StringRedisSerializer.serialize(StringRedisSerializer.java:36)
	at org.springframework.data.redis.core.AbstractOperations.rawValue(AbstractOperations.java:127)
	at org.springframework.data.redis.core.AbstractOperations.rawValues(AbstractOperations.java:135)
	at org.springframework.data.redis.core.DefaultZSetOperations.remove(DefaultZSetOperations.java:335)
	at com.easylive.mgs.stat.service.redis.AudienceRankCache.checkRejectedAudience(AudienceRankCache.java:92)
	at com.easylive.mgs.stat.job.RankCacheJob.checkRejectedAudience(RankCacheJob.java:72)
	at jdk.internal.reflect.GeneratedMethodAccessor184.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:835)

使用这个方法是传递了一个List导致报错 

	/**
	 * Remove {@code values} from sorted set. Return number of removed elements.
	 *
	 * @param key must not be {@literal null}.
	 * @param values must not be {@literal null}.
	 * @return {@literal null} when used in pipeline / transaction.
	 * @see Redis Documentation: ZREM
	 */
	@Nullable
	Long remove(K key, Object... values);

二、问题解决改成String数组

.toArray()

你可能感兴趣的:(Redis,JAVA)