mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
2f39c8a225
commit
27eae584fa
@ -105,7 +105,7 @@ public class FieldUtil {
|
||||
* @param name 字段名称
|
||||
* @return 字段对象,如果未找到返回{@code null}
|
||||
*/
|
||||
public static Field getDeClearField(final Class<?> beanClass, final String name) {
|
||||
public static Field getDeclearField(final Class<?> beanClass, final String name) {
|
||||
try {
|
||||
return beanClass.getDeclaredField(name);
|
||||
} catch (final NoSuchFieldException e) {
|
||||
|
@ -40,7 +40,7 @@ import java.lang.reflect.Method;
|
||||
public class MethodHandleUtil {
|
||||
|
||||
/**
|
||||
* 执行方法句柄,{@link MethodHandle#invoke(Object...)}包装<br>
|
||||
* 执行方法句柄,{@link MethodHandle#invokeWithArguments(Object...)}包装<br>
|
||||
*
|
||||
* @param methodHandle {@link MethodHandle}
|
||||
* @param args 方法参数值,支持子类转换和自动拆装箱
|
||||
|
@ -39,6 +39,10 @@ public class JdkUtil {
|
||||
* 是否Android环境
|
||||
*/
|
||||
public static final boolean IS_ANDROID;
|
||||
/**
|
||||
* 是否OPENJ9环境
|
||||
*/
|
||||
public static final boolean IS_OPENJ9;
|
||||
|
||||
static {
|
||||
// JVM版本
|
||||
@ -49,6 +53,7 @@ public class JdkUtil {
|
||||
// JVM名称
|
||||
final String jvmName = _getJvmName();
|
||||
IS_ANDROID = jvmName.equals("Dalvik");
|
||||
IS_OPENJ9 = jvmName.contains("OpenJ9");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024. looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* https://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.core.util;
|
||||
|
||||
import org.dromara.hutool.core.reflect.FieldUtil;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* {@link Unsafe}对象获取工具<br>
|
||||
* 参考:fastjson2/util/JDKUtils.java<br>
|
||||
* 此工具类通过反射获取,绕开安全检查。
|
||||
*
|
||||
* @author Looly
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public class UnsafeUtil {
|
||||
private static final Unsafe UNSAFE;
|
||||
|
||||
static {
|
||||
final String fieldName = JdkUtil.IS_ANDROID ? "THE_ONE" : "theUnsafe";
|
||||
final Field theUnsafeField = FieldUtil.getField(Unsafe.class, fieldName);
|
||||
UNSAFE = (Unsafe) FieldUtil.getStaticFieldValue(theUnsafeField);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{@link Unsafe}对象
|
||||
*
|
||||
* @return {@link Unsafe}
|
||||
*/
|
||||
public static Unsafe getUnsafe() {
|
||||
return UNSAFE;
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ public class FieldUtilTest {
|
||||
Assertions.assertNull(noField);
|
||||
|
||||
// 获取不到父类字段
|
||||
final Field field = FieldUtil.getDeClearField(ReflectUtilTest.TestSubClass.class, "field");
|
||||
final Field field = FieldUtil.getDeclearField(ReflectUtilTest.TestSubClass.class, "field");
|
||||
Assertions.assertNull(field);
|
||||
|
||||
final Field subField = FieldUtil.getField(ReflectUtilTest.TestSubClass.class, "subField");
|
||||
|
Loading…
x
Reference in New Issue
Block a user