Share

HtmlUnit

Tracker: Bugs

5 StackOverflowError parsing JavaScript style tags - ID: 2892191
Last Update: Comment added ( ben-flynn )

I encountered an occasional StackOverflowError in the following method:

com.gargoylesoftware.htmlunit.javascript.regexp.HtmlUnitRegExpProxy.doActio
n()

I found it was related to the following Pattern / Matcher and recreated it
outside of HtmlUnit (I will attach scriptText2.txt).

private static void matchTest() {
try {
BufferedReader reader = new BufferedReader(new
FileReader("scriptText2.txt"));
StringBuffer buffer = new StringBuffer();
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line + "\n");
}
int i = Pattern.CASE_INSENSITIVE;
Pattern pattern = Pattern.compile("<style\\b(\\s|.)*?<\\/style>", i);
Matcher matcher = pattern.matcher(buffer.toString());
System.out.println(matcher.find());
}
catch (StackOverflowError er) {
System.err.println("STACK OVERFLOW");
System.exit(0);
}
}

That code resulted in a StackOverflowError with no arguments passed to
Java, or if I forced a reasonably low stack size e.g. -Xss256k. Java's
behavior
seems deeply recursive here.

I found that increasing my java stack size ( -Xss1m ) resolved the issue,
but also found that, for my case I was able to take the newlines out of
"buffer" and
change my regex pattern to: <style\\b.*?<\\/style>

I realize that, in a sense, there is not a bug here or that, if there is,
it may be more an issue with Java's pattern matching, but thought it was
worth bringing
to your attention, as I imagine others might run into this issue. Sorry
that I have not tried it in the latest nightly build, unfortunately time
constraints
have not yet allowed me to do so.

I am using JRE1.6.0_17.


Benjamin Flynn ( ben-flynn ) - 2009-11-04 21:25

5

Open

None

Nobody/Anonymous

None

2.6

Public


Comments ( 2 )

Date: 2009-11-05 18:45
Sender: ben-flynn

Just tried it with JRE 1.5.0_22 and observed the StackOverflowError
(compiling in Eclipse, switched libraries in my build path, verified with
System.out.println(System.getProperty("java.version"))). Perhaps an
earlier version of Java 5 might do something different.


Date: 2009-11-05 11:48
Sender: mguillemProject Admin

Did you check it with Java 5?
I've already encountered a similar problem where it was working fine with
Java 5 but threw a StackOverflowError with Java 6.


Attached File ( 1 )

Filename Description Download
scriptText2.txt Sample text from actual js that causes StackOverflowError Download

Change ( 1 )

Field Old Value Date By
File Added 349567: scriptText2.txt 2009-11-04 21:25 ben-flynn