mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix getFieldValue and add test
This commit is contained in:
parent
c804ebfbc1
commit
bddb97704e
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
* 【core 】 新增WatchServer(issue#440@Github)
|
* 【core 】 新增WatchServer(issue#440@Github)
|
||||||
|
* 【core 】 ReflectUtil.getFieldValue支持static(issue#662@Github)
|
||||||
|
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
|
@ -214,13 +214,13 @@ public class ReflectUtil {
|
|||||||
/**
|
/**
|
||||||
* 获取字段值
|
* 获取字段值
|
||||||
*
|
*
|
||||||
* @param obj 对象
|
* @param obj 对象,static字段则此字段为null
|
||||||
* @param field 字段
|
* @param field 字段
|
||||||
* @return 字段值
|
* @return 字段值
|
||||||
* @throws UtilException 包装IllegalAccessException异常
|
* @throws UtilException 包装IllegalAccessException异常
|
||||||
*/
|
*/
|
||||||
public static Object getFieldValue(Object obj, Field field) throws UtilException {
|
public static Object getFieldValue(Object obj, Field field) throws UtilException {
|
||||||
if (null == obj || null == field) {
|
if (null == field) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
setAccessible(field);
|
setAccessible(field);
|
||||||
@ -228,7 +228,7 @@ public class ReflectUtil {
|
|||||||
try {
|
try {
|
||||||
result = field.get(obj);
|
result = field.get(obj);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new UtilException(e, "IllegalAccess for {}.{}", obj.getClass(), field.getName());
|
throw new UtilException(e, "IllegalAccess for {}.{}", field.getDeclaringClass(), field.getName());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -274,13 +274,12 @@ public class ReflectUtil {
|
|||||||
/**
|
/**
|
||||||
* 设置字段值
|
* 设置字段值
|
||||||
*
|
*
|
||||||
* @param obj 对象
|
* @param obj 对象,如果是static字段,此参数为null
|
||||||
* @param field 字段
|
* @param field 字段
|
||||||
* @param value 值,值类型必须与字段类型匹配,不会自动转换对象类型
|
* @param value 值,值类型必须与字段类型匹配,不会自动转换对象类型
|
||||||
* @throws UtilException UtilException 包装IllegalAccessException异常
|
* @throws UtilException UtilException 包装IllegalAccessException异常
|
||||||
*/
|
*/
|
||||||
public static void setFieldValue(Object obj, Field field, Object value) throws UtilException {
|
public static void setFieldValue(Object obj, Field field, Object value) throws UtilException {
|
||||||
Assert.notNull(obj);
|
|
||||||
Assert.notNull(field, "Field in [{}] not exist !", obj.getClass().getName());
|
Assert.notNull(field, "Field in [{}] not exist !", obj.getClass().getName());
|
||||||
|
|
||||||
setAccessible(field);
|
setAccessible(field);
|
||||||
|
@ -37,6 +37,18 @@ public class SmTest {
|
|||||||
Assert.assertEquals(content, decryptStr);
|
Assert.assertEquals(content, decryptStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sm4Test2() {
|
||||||
|
String content = "test中文";
|
||||||
|
SM4 sm4 = new SM4(Mode.CTR, Padding.PKCS5Padding);
|
||||||
|
sm4.setIv("aaaabbbb".getBytes());
|
||||||
|
|
||||||
|
String encryptHex = sm4.encryptHex(content);
|
||||||
|
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||||
|
|
||||||
|
Assert.assertEquals(content, decryptStr);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sm4ECBPKCS5PaddingTest2() {
|
public void sm4ECBPKCS5PaddingTest2() {
|
||||||
String content = "test中文";
|
String content = "test中文";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user