Created attachment 36889 [details] Data for investigation A thread is continuously occupied by POI and no response is returned when the Excel SUBSTITUTE function is called. It occurs when the second argument is blank(empty character). However, it doesn't occur when using the same function on Microsoft Excel.(only occurs when calling from POI) I called POI, which reads an Excel file with SUBSTITUTE function in some CELLs, from a web application deployed on GlassFish. According to the thread dump, it seems that the thread has stopped at the line marked with "*" on the following code. ------------------------------------------------------------- org.apache.poi.ss.formula.functions.Substitute private static String replaceAllOccurrences(String oldStr, String searchStr, String newStr) { StringBuffer sb = new StringBuffer(); int startIndex = 0; int nextMatch = -1; while (true) { nextMatch = oldStr.indexOf(searchStr, startIndex); if (nextMatch < 0) { // store everything from end of last match to end of string sb.append(oldStr.substring(startIndex)); return sb.toString(); } // store everything from end of last match to start of this match sb.append(oldStr.substring(startIndex, nextMatch)); sb.append(newStr); * startIndex = nextMatch + searchStr.length(); } } ------------------------------------------------------------- It occurs when using version 4.1.1, too. If the allocated Java heap memory is small, java.lang.OutOfMemoryError is thrown instead. I've attached the following materials that are necessary for the survey. 1. SUBSTITUTE.xls:Excel file which the problem occurs. 2. OutOfMemory.txt:Stack trace when java.lang.OutOfMemoryError was thrown. 3. ThreadDump.txt:Excerpt of the thread dump obtained when no response occurred.
Fixed via r1872145, there was an endless loop whenever an empty string was used as "search string".