Skip to content

Commit

Permalink
fix null check
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Dec 6, 2018
1 parent daeb6fe commit ad95ce2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### 新特性
* 【core】 增加TypeReference类(issue#IPAML@Gitee)
* 【json】 支持TypeReference类转换,并对toBean逻辑做了大量变动(issue#IPAML@Gitee)
* 【core】 ArrayUtil.get和CollUtil.get返回null而非空指针(issue#IPKZO@Gitee)

### Bug修复

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,10 @@ public static <T> List<T> addAllIfNotContains(List<T> list, List<T> otherList) {
* @since 4.0.6
*/
public static <T> T get(Collection<T> collection, int index) {
if(null == collection) {
return null;
}

final int size = collection.size();
if (index < 0) {
index += size;
Expand Down
4 changes: 4 additions & 0 deletions hutool-core/src/main/java/cn/hutool/core/util/ArrayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,10 @@ public static boolean isArray(Object obj) {
*/
@SuppressWarnings("unchecked")
public static <T> T get(Object array, int index) {
if(null == array) {
return null;
}

if (index < 0) {
index += Array.getLength(array);
}
Expand Down

0 comments on commit ad95ce2

Please sign in to comment.