I have a suite of unit tests in a hybris based project, whenever I try to tun the test suite from the IDE I get the following stack trace saying that an java.lang.StackOverflowError
occured.
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)
This is the code for the 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);
}
}
If you look closely at this part of your function :
if (newValue == null) {
newValue = props.getProperty(newKey);
if (newValue != null && newValue.contains("${")) {
expandProperty(newValue, platformConfig, props, newKey);
newValue = props.getProperty(newKey);
}
}
if newValue == null
is true and newValue != null && newValue.contains("${")
is true, then
expandProperty(newValue, platformConfig, props, newKey);
will be executed, and expandProperty
get called again with the same values and expandProperty(newValue, platformConfig, props, newKey);
will be executed again, that's generate an infinite call to this same function, and triggers StackOverFlowError Exception
Hope this hepls