Bug 63940 - POI continues to occupy a thread and no response is returned when calling the Excel SUBSTITUTE function.
Summary: POI continues to occupy a thread and no response is returned when calling the...
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: unspecified
Hardware: All All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2019-11-20 06:05 UTC by Machiko Hashimoto
Modified: 2019-12-31 16:53 UTC (History)
0 users

Data for investigation (11.57 KB, application/x-zip-compressed)
2019-11-20 06:05 UTC, Machiko Hashimoto

Note You need to log in before you can comment on or make changes to this bug.
Description Machiko Hashimoto 2019-11-20 06:05:25 UTC
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.


	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
				return sb.toString();
			// store everything from end of last match to start of this match
			sb.append(oldStr.substring(startIndex, nextMatch));
*			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.
Comment 1 Dominik Stadler 2019-12-31 16:53:24 UTC
Fixed via r1872145, there was an endless loop whenever an empty string was used as "search string".