我在基于Hybris的项目中有一套单元测试,每当我尝试从IDE调整测试套件时,我都会得到以下堆栈跟踪,表明发生了java.lang.StackOverflowError
。
Error:Hybris Model Source Generating Compiler: Error: java.lang.StackOverflowError
java.lang.StackOverflowError
at java.util.regex.Pattern.range(Pattern.java:2635)
at java.util.regex.Pattern.clazz(Pattern.java:2564)
at java.util.regex.Pattern.sequence(Pattern.java:2065)
at java.util.regex.Pattern.expr(Pattern.java:1998)
at java.util.regex.Pattern.compile(Pattern.java:1698)
at java.util.regex.Pattern.<init>(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:589)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
at de.hybris.bootstrap.config.ConfigUtil.expandProperty(ConfigUtil.java:603)
这是de.hybris.bootstrap.config.ConfigUtil.expandProperty
private static void expandProperty(String value, PlatformConfig platformConfig, Properties props, String key) {
String replacement = "";
int lastIndex = 0;
Pattern pattern = Pattern.compile("\\$\\{[^\\}]*\\}");
Matcher matcher = pattern.matcher(value);
for(String newKey = null; matcher.find(); lastIndex = matcher.end()) {
replacement = replacement + value.substring(lastIndex, matcher.start());
newKey = matcher.group().substring(2, matcher.group().length() - 1);
String newValue = platformConfig.getSystemConfig().getDir(newKey);
if (newValue == null) {
newValue = props.getProperty(newKey);
if (newValue != null && newValue.contains("${")) {
expandProperty(newValue, platformConfig, props, newKey);
newValue = props.getProperty(newKey);
}
}
if (newValue == null) {
replacement = replacement + matcher.group();
} else {
replacement = replacement + newValue;
}
}
if (lastIndex < value.length()) {
replacement = replacement + value.substring(lastIndex, value.length());
}
if (key != null) {
props.put(key, replacement);
}
}
答案 0 :(得分:1)
如果您仔细查看功能的这一部分:
if (newValue == null) {
newValue = props.getProperty(newKey);
if (newValue != null && newValue.contains("${")) {
expandProperty(newValue, platformConfig, props, newKey);
newValue = props.getProperty(newKey);
}
}
如果newValue == null
为真且newValue != null && newValue.contains("${")
为真,则
expandProperty(newValue, platformConfig, props, newKey);
将被执行,并以相同的值再次expandProperty
被调用,并且expandProperty(newValue, platformConfig, props, newKey);
将被再次执行,这将生成对该函数的无限调用,并触发 StackOverFlowError >例外
希望这个帮助