From 9c80d8adc3642cbbfe92f4ea837e3f159d99aafa Mon Sep 17 00:00:00 2001 From: yx9o Date: Mon, 23 Feb 2026 00:02:38 +0800 Subject: [PATCH] [ISSUE #10105] Fix ClassCastException in getLocks() method --- .../lock/AdaptiveBackOffSpinLockImpl.java | 5 ++- .../lock/AdaptiveBackOffSpinLockImplTest.java | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 store/src/test/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImplTest.java diff --git a/store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java b/store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java index 1dfbd4718b8..3c0de976448 100644 --- a/store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java +++ b/store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java @@ -20,6 +20,7 @@ import java.time.LocalTime; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -166,8 +167,8 @@ public void swap() { } } - public List getLocks() { - return (List) this.locks.values(); + public Collection getLocks() { + return this.locks.values(); } public void setLocks(Map locks) { diff --git a/store/src/test/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImplTest.java b/store/src/test/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImplTest.java new file mode 100644 index 00000000000..a210f55b77c --- /dev/null +++ b/store/src/test/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImplTest.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.store.lock; + +import org.junit.Test; + +import java.util.Collection; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class AdaptiveBackOffSpinLockImplTest { + + @Test + public void testGetLocks() { + AdaptiveBackOffSpinLockImpl lockImpl = new AdaptiveBackOffSpinLockImpl(); + Collection locks = lockImpl.getLocks(); + assertEquals(2, locks.size()); + for (AdaptiveBackOffSpinLock lock : locks) { + assertNotNull(lock); + } + } +}