mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复PathUtil.getMimeType可能造成的异常
This commit is contained in:
parent
050f312c56
commit
161edefaf2
@ -2,7 +2,7 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.21(2023-06-27)
|
||||
# 5.8.21(2023-06-29)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 list 为空时,CollUtil.max等返回null而非异常(pr#1027@Gitee)
|
||||
@ -13,6 +13,7 @@
|
||||
* 【core 】 修复MapUtil工具使用filter方法构造传入参数结果问题(issue#3162@Github)
|
||||
* 【core 】 修复序列化和反序列化Class问题(issue#I7FQ29@Gitee)
|
||||
* 【setting】 修复utf8-bom的setting文件读取问题(issue#I7G34E@Gitee)
|
||||
* 【core 】 修复PathUtil.getMimeType可能造成的异常(issue#3179@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.20(2023-06-16)
|
||||
|
@ -620,8 +620,9 @@ public class PathUtil {
|
||||
public static String getMimeType(Path file) {
|
||||
try {
|
||||
return Files.probeContentType(file);
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
} catch (IOException ignore) {
|
||||
// issue#3179,使用OpenJDK可能抛出NoSuchFileException,此处返回null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,12 @@ public class PathUtilTest {
|
||||
Assert.assertEquals("application/x-7z-compressed", contentType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issue3179Test() {
|
||||
final String mimeType = PathUtil.getMimeType(Paths.get("xxxx.jpg"));
|
||||
Assert.assertEquals("image/jpeg", mimeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* issue#2893 target不存在空导致异常
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user