mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
修复SettingLoader
load未抛出异常导致配置文件无法正常遍历的问题(pr#3868@Github)
This commit is contained in:
parent
381bc9c229
commit
7f2f134068
@ -1240,11 +1240,11 @@ public class FileUtil {
|
|||||||
if (null == classPath) {
|
if (null == classPath) {
|
||||||
// throw new NullPointerException("ClassPath is null !");
|
// throw new NullPointerException("ClassPath is null !");
|
||||||
// 在jar运行模式中,ClassPath有可能获取不到,此时返回原始相对路径(此时获取的文件为相对工作目录)
|
// 在jar运行模式中,ClassPath有可能获取不到,此时返回原始相对路径(此时获取的文件为相对工作目录)
|
||||||
return path;
|
return normalPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 资源不存在的情况下使用标准化路径有问题,使用原始路径拼接后标准化路径
|
// 资源不存在的情况下使用标准化路径有问题,使用原始路径拼接后标准化路径
|
||||||
return FileNameUtil.normalize(classPath.concat(Objects.requireNonNull(path)));
|
return FileNameUtil.normalize(classPath.concat(Objects.requireNonNull(normalPath)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +19,7 @@ package org.dromara.hutool.setting;
|
|||||||
import org.dromara.hutool.core.io.IoUtil;
|
import org.dromara.hutool.core.io.IoUtil;
|
||||||
import org.dromara.hutool.core.io.LineReader;
|
import org.dromara.hutool.core.io.LineReader;
|
||||||
import org.dromara.hutool.core.io.file.FileUtil;
|
import org.dromara.hutool.core.io.file.FileUtil;
|
||||||
|
import org.dromara.hutool.core.io.resource.NoResourceException;
|
||||||
import org.dromara.hutool.core.io.resource.Resource;
|
import org.dromara.hutool.core.io.resource.Resource;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import org.dromara.hutool.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.regex.ReUtil;
|
import org.dromara.hutool.core.regex.ReUtil;
|
||||||
@ -132,23 +133,26 @@ public class SettingLoader {
|
|||||||
*
|
*
|
||||||
* @param resource 配置文件URL
|
* @param resource 配置文件URL
|
||||||
* @return 加载是否成功
|
* @return 加载是否成功
|
||||||
|
* @throws NoResourceException 如果资源不存在,抛出此异常
|
||||||
*/
|
*/
|
||||||
public GroupedMap load(final Resource resource) {
|
public GroupedMap load(final Resource resource) throws NoResourceException{
|
||||||
if (resource == null) {
|
Assert.notNull(resource, "Null setting url define!");
|
||||||
throw new NullPointerException("Null setting url define!");
|
|
||||||
}
|
GroupedMap groupedMap;
|
||||||
log.debug("Load setting file [{}]", resource);
|
|
||||||
InputStream settingStream = null;
|
InputStream settingStream = null;
|
||||||
try {
|
try {
|
||||||
settingStream = resource.getStream();
|
settingStream = resource.getStream();
|
||||||
return load(settingStream);
|
groupedMap = load(settingStream);
|
||||||
|
log.debug("Load setting file [{}]", resource);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
log.error(e, "Load setting error!");
|
if(e instanceof NoResourceException){
|
||||||
// 加载错误跳过,返回空的map
|
throw (NoResourceException)e;
|
||||||
return new GroupedMap();
|
}
|
||||||
|
throw new NoResourceException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.closeQuietly(settingStream);
|
IoUtil.closeQuietly(settingStream);
|
||||||
}
|
}
|
||||||
|
return groupedMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user