Skip to content

Commit 45466b7

Browse files
committed
Fix TestJdbcWithMiniHS2.
1 parent 49dca72 commit 45466b7

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

common/src/java/org/apache/hive/common/util/ReflectionUtil.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class ReflectionUtil {
4848
// not caching that many constructors.
4949
// Note that weakKeys causes "==" to be used for key compare; this will only work
5050
// for classes in the same classloader. Should be ok in this case.
51-
private static final Cache<Class<?>, Constructor<?>> CONSTRUCTOR_CACHE =
51+
private static Cache<Class<?>, Constructor<?>> CONSTRUCTOR_CACHE =
5252
CacheBuilder.newBuilder().expireAfterAccess(15, TimeUnit.MINUTES)
5353
.concurrencyLevel(64)
5454
.weakKeys().weakValues().build();
@@ -174,18 +174,6 @@ public static void setInAllFields(Object object, String field, Object value) {
174174
}
175175
}
176176

177-
public static void setStaticFinalFieldsModifiable(Field field) {
178-
try {
179-
field.setAccessible(true);
180-
VarHandle modifiersHandle = MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup())
181-
.findVarHandle(Field.class, "modifiers", int.class);
182-
int modifiers = field.getModifiers();
183-
modifiersHandle.set(field, modifiers & ~Modifier.FINAL);
184-
} catch (NoSuchFieldException | IllegalAccessException e) {
185-
throw new RuntimeException("Cannot make static final field %s modifiable".formatted(field));
186-
}
187-
}
188-
189177
public static List<InstanceField> allDeclaredFieldsOf(Object testInstance) {
190178
List<InstanceField> result = new ArrayList<>();
191179
for (Class<?> clazz = testInstance.getClass();

itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
import org.junit.Assert;
8989
import org.junit.BeforeClass;
9090
import org.junit.Test;
91+
import sun.misc.Unsafe;
92+
9193
import static org.apache.hadoop.hive.common.repl.ReplConst.SOURCE_OF_REPLICATION;
9294

9395
public class TestJdbcWithMiniHS2 {
@@ -1235,11 +1237,11 @@ private void setReflectionUtilCache() {
12351237
try {
12361238
constructorCacheField = ReflectionUtil.class.getDeclaredField("CONSTRUCTOR_CACHE");
12371239
if (constructorCacheField != null) {
1238-
ReflectionUtil.setStaticFinalFieldsModifiable(constructorCacheField);
12391240
tmp =
12401241
CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.SECONDS).concurrencyLevel(64)
12411242
.weakKeys().weakValues().build();
1242-
constructorCacheField.set(tmp.getClass(), tmp);
1243+
constructorCacheField.setAccessible(true);
1244+
constructorCacheField.set(null, tmp);
12431245
}
12441246
} catch (Exception e) {
12451247
System.out.println("Error when setting the CONSTRUCTOR_CACHE to expire: " + e);

0 commit comments

Comments
 (0)