mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix NPE bug
This commit is contained in:
parent
aaa88dad81
commit
8196941b6e
@ -25,6 +25,7 @@
|
|||||||
* 【core 】 修复urlWithParamIfGet函数逻辑问题(issue#I50IUD@Gitee)
|
* 【core 】 修复urlWithParamIfGet函数逻辑问题(issue#I50IUD@Gitee)
|
||||||
* 【core 】 修复IoUtil.readBytes限制长度读取问题(issue#2230@Github)
|
* 【core 】 修复IoUtil.readBytes限制长度读取问题(issue#2230@Github)
|
||||||
* 【http 】 修复HttpRequest中编码对URL无效的问题(issue#I50NHQ@Gitee)
|
* 【http 】 修复HttpRequest中编码对URL无效的问题(issue#I50NHQ@Gitee)
|
||||||
|
* 【poi 】 修复读取excel抛NPE错误(pr#2234@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据结果集处理辅助类
|
* 数据结果集处理辅助类
|
||||||
*
|
*
|
||||||
* @author loolly
|
* @author loolly
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -60,7 +60,7 @@ public class HandleHelper {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T handleRow(int columnCount, ResultSetMetaData meta, ResultSet rs, Class<T> beanClass) throws SQLException {
|
public static <T> T handleRow(int columnCount, ResultSetMetaData meta, ResultSet rs, Class<T> beanClass) throws SQLException {
|
||||||
Assert.notNull(beanClass, "Bean Class must be not null !");
|
Assert.notNull(beanClass, "Bean Class must be not null !");
|
||||||
|
|
||||||
if(beanClass.isArray()) {
|
if(beanClass.isArray()) {
|
||||||
//返回数组
|
//返回数组
|
||||||
final Class<?> componentType = beanClass.getComponentType();
|
final Class<?> componentType = beanClass.getComponentType();
|
||||||
@ -81,7 +81,7 @@ public class HandleHelper {
|
|||||||
final Object[] objRow = handleRow(columnCount, meta, rs, Object[].class);
|
final Object[] objRow = handleRow(columnCount, meta, rs, Object[].class);
|
||||||
return (T) StrUtil.join(", ", objRow);
|
return (T) StrUtil.join(", ", objRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
//普通bean
|
//普通bean
|
||||||
final T bean = ReflectUtil.newInstanceIfPossible(beanClass);
|
final T bean = ReflectUtil.newInstanceIfPossible(beanClass);
|
||||||
//忽略字段大小写
|
//忽略字段大小写
|
||||||
@ -108,7 +108,7 @@ public class HandleHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理单条数据
|
* 处理单条数据
|
||||||
*
|
*
|
||||||
* @param columnCount 列数
|
* @param columnCount 列数
|
||||||
* @param meta ResultSetMetaData
|
* @param meta ResultSetMetaData
|
||||||
* @param rs 数据集
|
* @param rs 数据集
|
||||||
@ -118,10 +118,10 @@ public class HandleHelper {
|
|||||||
public static Entity handleRow(int columnCount, ResultSetMetaData meta, ResultSet rs) throws SQLException {
|
public static Entity handleRow(int columnCount, ResultSetMetaData meta, ResultSet rs) throws SQLException {
|
||||||
return handleRow(columnCount, meta, rs, false);
|
return handleRow(columnCount, meta, rs, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理单条数据
|
* 处理单条数据
|
||||||
*
|
*
|
||||||
* @param columnCount 列数
|
* @param columnCount 列数
|
||||||
* @param meta ResultSetMetaData
|
* @param meta ResultSetMetaData
|
||||||
* @param rs 数据集
|
* @param rs 数据集
|
||||||
@ -136,7 +136,7 @@ public class HandleHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理单条数据
|
* 处理单条数据
|
||||||
*
|
*
|
||||||
* @param <T> Entity及其子对象
|
* @param <T> Entity及其子对象
|
||||||
* @param row Entity对象
|
* @param row Entity对象
|
||||||
* @param columnCount 列数
|
* @param columnCount 列数
|
||||||
@ -199,7 +199,7 @@ public class HandleHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理多条数据
|
* 处理多条数据
|
||||||
*
|
*
|
||||||
* @param <T> 集合类型
|
* @param <T> 集合类型
|
||||||
* @param rs 数据集
|
* @param rs 数据集
|
||||||
* @param collection 数据集
|
* @param collection 数据集
|
||||||
@ -209,10 +209,10 @@ public class HandleHelper {
|
|||||||
public static <T extends Collection<Entity>> T handleRs(ResultSet rs, T collection) throws SQLException {
|
public static <T extends Collection<Entity>> T handleRs(ResultSet rs, T collection) throws SQLException {
|
||||||
return handleRs(rs, collection, false);
|
return handleRs(rs, collection, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理多条数据
|
* 处理多条数据
|
||||||
*
|
*
|
||||||
* @param <T> 集合类型
|
* @param <T> 集合类型
|
||||||
* @param rs 数据集
|
* @param rs 数据集
|
||||||
* @param collection 数据集
|
* @param collection 数据集
|
||||||
@ -234,7 +234,7 @@ public class HandleHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理多条数据并返回一个Bean列表
|
* 处理多条数据并返回一个Bean列表
|
||||||
*
|
*
|
||||||
* @param <E> 集合元素类型
|
* @param <E> 集合元素类型
|
||||||
* @param <T> 集合类型
|
* @param <T> 集合类型
|
||||||
* @param rs 数据集
|
* @param rs 数据集
|
||||||
@ -259,8 +259,7 @@ public class HandleHelper {
|
|||||||
/**
|
/**
|
||||||
* 获取字段值<br>
|
* 获取字段值<br>
|
||||||
* 针对日期时间等做单独处理判断
|
* 针对日期时间等做单独处理判断
|
||||||
*
|
*
|
||||||
* @param <T> 返回类型
|
|
||||||
* @param rs {@link ResultSet}
|
* @param rs {@link ResultSet}
|
||||||
* @param columnIndex 字段索引
|
* @param columnIndex 字段索引
|
||||||
* @param type 字段类型,默认Object
|
* @param type 字段类型,默认Object
|
||||||
@ -268,7 +267,7 @@ public class HandleHelper {
|
|||||||
* @return 字段值
|
* @return 字段值
|
||||||
* @throws SQLException SQL异常
|
* @throws SQLException SQL异常
|
||||||
*/
|
*/
|
||||||
private static <T> Object getColumnValue(ResultSet rs, int columnIndex, int type, Type targetColumnType) throws SQLException {
|
private static Object getColumnValue(ResultSet rs, int columnIndex, int type, Type targetColumnType) throws SQLException {
|
||||||
Object rawValue = null;
|
Object rawValue = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Types.TIMESTAMP:
|
case Types.TIMESTAMP:
|
||||||
|
@ -245,9 +245,9 @@ public class ExcelReadTest {
|
|||||||
Assert.assertEquals("", objects.get(2));
|
Assert.assertEquals("", objects.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
@Ignore
|
|
||||||
public void readColumnNPETest() {
|
public void readColumnNPETest() {
|
||||||
|
// https://github.com/dromara/hutool/pull/2234
|
||||||
ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("read_row_npe.xlsx"));
|
ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("read_row_npe.xlsx"));
|
||||||
reader.readColumn(0, 1);
|
reader.readColumn(0, 1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user