this case produces Stack OverFlow Error //contents is my string to parse String contents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Ticket><!--Ticket Data-- <RequestNr>558</RequestNr><SapOrderNr>0000000558/1</SapOrderNr><RequestUrl></Req uestUrl><RequesterName>Alain Lacour</RequesterName><RequestDate>26.02.2001</RequestDate><RequestSeat></Reques tSeat><UserData><!--User identification data--><LongName>SUPER TOTO</LongName><PersNo></PersNo><LastName></LastName><FirstName></FirstName><Uni queID></UniqueID><EmailAddress></EmailAddress><Office></Office><Phone></Phone><R ef></Ref></UserData><ReceiverData><!--Receiver identification data-- ><PersNo></PersNo><LastName>Gebus</LastName><FirstName>Pascal</FirstName><Unique ID>GEBUSPA1</UniqueID><EmailAddress>pascal.gebus@mhinformatics.com</EmailAddress ><Office>WSJ-210.416</Office><Phone>+41 61 32 42 468</Phone><Ref>MH</Ref></ReceiverData><AddDevice><!--Device Data-- ><DeviceName>Dock zu TP T600</DeviceName><HWGroup>ACCESSORY</HWGroup><WkstClass></WkstClass><LocalAdminR ights></LocalAdminRights><ReferenceWkst></ReferenceWkst>" +"<DeviceModel></DeviceModel><CostCenter></CostCenter><HardwareRef></HardwareRef ><Domain></Domain><Network></Network><DeliveryLocation>WSJ- 210.416</DeliveryLocation><AssignToDevice><DeviceID>New system</DeviceID> <DeviceLocation>WSJ- 210.416</DeviceLocation></AssignToDevice></AddDevice><ProblemData><!--Service information--><ProblemDescription>hello support</ProblemDescription></ProblemData></Ticket>" +"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Ticket><!--Ticket Data-- ><RequestNr>558</RequestNr><SapOrderNr>0000000558/1</SapOrderNr><RequestUrl></Re questUrl><RequesterName>Alain Lacour</RequesterName><RequestDate>26.02.2001</RequestDate><RequestSeat></Reques tSeat><UserData><!--User identification data--><LongName>SUPER TOTO</LongName><PersNo></PersNo><LastName></LastName><FirstName></FirstName><Uni queID></UniqueID><EmailAddress></EmailAddress><Office></Office><Phone></Phone><R ef></Ref></UserData><ReceiverData><!--Receiver identification data-- ><PersNo></PersNo><LastName>Gebus</LastName><FirstName>Pascal</FirstName><Unique ID>GEBUSPA1</UniqueID><EmailAddress>pascal.gebus@mhinformatics.com</EmailAddress ><Office>WSJ-210.416</Office><Phone>+41 61 32 42 468</Phone><Ref>MH</Ref></ReceiverData><AddDevice><!--Device Data-- ><DeviceName>Dock zu TP T600</DeviceName><HWGroup>ACCESSORY</HWGroup><WkstClass></WkstClass><LocalAdminR ights></LocalAdminRights><ReferenceWkst></ReferenceWkst><DeviceModel></DeviceMod el>" +"<CostCenter></CostCenter><HardwareRef></HardwareRef><Domain></Domain><Network> </Network><DeliveryLocation>WSJ- 210.416</DeliveryLocation><AssignToDevice><DeviceID>New system</DeviceID> <DeviceLocation>WSJ- 210.416</DeviceLocation></AssignToDevice></AddDevice><ProblemData><!--Service information--><ProblemDescription>hello support</ProblemDescription></ProblemData></Ticket>" +"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Ticket><!--Ticket Data-- ><RequestNr>558</RequestNr><SapOrderNr>0000000558/2</SapOrderNr><RequestUrl></Re questUrl><RequesterName>Alain Lacour</RequesterName><RequestDate>26.02.2001</RequestDate><RequestSeat></Reques tSeat><UserData><!--User identification data--><LongName>SUPER TOTO</LongName><PersNo></PersNo><LastName></LastName><FirstName></FirstName><Uni queID></UniqueID><EmailAddress></EmailAddress><Office></Office><Phone></Phone><R ef></Ref></UserData><ReceiverData><!--Receiver identification data-- ><PersNo></PersNo><LastName>Gebus</LastName><FirstName>Pascal</FirstName><Unique ID>GEBUSPA1</UniqueID><EmailAddress>pascal.gebus@mhinformatics.com</EmailAddress ><Office>WSJ-210.416</Office><Phone>+41 61 32 42 468</Phone><Ref>MH</Ref></ReceiverData><AddDevice><!--Device Data-- ><DeviceName>3T Mouse</DeviceName><HWGroup>PERIPHERAL</HWGroup><WkstClass></WkstClass><LocalAdmi nRights></LocalAdminRights><ReferenceWkst></ReferenceWkst><DeviceModel>3T MOUSE</DeviceModel>" +"<CostCenter></CostCenter><HardwareRef></HardwareRef><Domain></Domain><Network> </Network><DeliveryLocation>WSJ-210.416</DeliveryLocation><AssignToDevice> <DeviceID>New system</DeviceID><DeviceLocation>WSJ- 210.416</DeviceLocation></AssignToDevice></AddDevice><ProblemData><!--Service information--><ProblemDescription>hello support</ProblemDescription></ProblemData></Ticket>" +"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Ticket><!--Ticket Data-- ><RequestNr>558</RequestNr><SapOrderNr>0000000558/3</SapOrderNr><RequestUrl></Re questUrl><RequesterName>Alain Lacour</RequesterName><RequestDate>26.02.2001</RequestDate><RequestSeat></Reques tSeat><UserData><!--User identification data--><LongName>SUPER TOTO</LongName><PersNo></PersNo><LastName></LastName><FirstName></FirstName><Uni queID></UniqueID><EmailAddress></EmailAddress><Office></Office><Phone></Phone><R ef></Ref></UserData><ReceiverData><!--Receiver identification data-- ><PersNo></PersNo><LastName>Gebus</LastName><FirstName>Pascal</FirstName><Unique ID>GEBUSPA1</UniqueID><EmailAddress>pascal.gebus@mhinformatics.com</EmailAddress ><Office>WSJ-210.416</Office><Phone>+41 61 32 42 468</Phone><Ref>MH</Ref></ReceiverData><AddDevice><!--Device Data-- ><DeviceName>test for xml mail</DeviceName><HWGroup></HWGroup><WkstClass></WkstClass><LocalAdminRights></L ocalAdminRights><ReferenceWkst></ReferenceWkst><DeviceModel></DeviceModel>" +"<CostCenter></CostCenter><HardwareRef></HardwareRef><Domain></Domain><Network> </Network><DeliveryLocation>WSJ- 210.416</DeliveryLocation><AssignToDevice><DeviceID>New system</DeviceID><DeviceLocation>WSJ- 210.416</DeviceLocation></AssignToDevice></AddDevice><ProblemData><!--Service information--><ProblemDescription>hello support</ProblemDescription></ProblemData></Ticket>" ; // org.apache.regexp.RE r = new org.apache.regexp.RE ("<Ticket> (.|[\n\r])*</Ticket>") ; if(r.match(contents.toString())) { String expr = r.getParen(0); } // it produces this Error : java.lang.StackOverflowError at org.apache.regexp.StringCharacterIterator.isEnd (StringCharacterIterator.java:96) at org.apache.regexp.RE.matchNodes(RE.java:1121) at org.apache.regexp.RE.matchNodes(RE.java:1376) at org.apache.regexp.RE.matchNodes(RE.java:910) at org.apache.regexp.RE.matchNodes(RE.java:1376) at org.apache.regexp.RE.matchNodes(RE.java:933) at org.apache.regexp.RE.matchNodes(RE.java:1376) at org.apache.regexp.RE.matchNodes(RE.java:910) at org.apache.regexp.RE.matchNodes(RE.java:1376) at org.apache.regexp.RE.matchNodes(RE.java:933) at org.apache.regexp.RE.matchNodes(RE.java:1376) at org.apache.regexp.RE.matchNodes(RE.java:910) at org.apache.regexp.RE.matchNodes(RE.java:1376) // I'm using JDK1.3 and Regexp1.2 // this example works with JDK1.2.2 Thanks, Isabelle Lieu
Have you tried to start java with bigger native thread stack/ Java stack (-ss and -oss command line options)?
Setting the stack size on version 1.3 work on Solaris, but doesn't under WinNT 4.0. Java version 1.3.1 Beta has the problem too. We use Jakarta 1.1 and the output is : Exception in thread "main" java.lang.StackOverflowError at org.apache.regexp.RE.matchNodes(RE.java:1358) at org.apache.regexp.RE.matchNodes(RE.java:927) at org.apache.regexp.RE.matchNodes(RE.java:1358) at org.apache.regexp.RE.matchNodes(RE.java:904) at org.apache.regexp.RE.matchNodes(RE.java:1358) at org.apache.regexp.RE.matchNodes(RE.java:927) at org.apache.regexp.RE.matchNodes(RE.java:1358) at org.apache.regexp.RE.matchNodes(RE.java:904) at org.apache.regexp.RE.matchNodes(RE.java:1358) at org.apache.regexp.RE.matchNodes(RE.java:927) ...
I'm having similiar problems too. It looks like for longer matches the RE class is getting problems when you have wildcards (like .*) in the regular expression you are trying to match against. Especially in a case like Isabelle's example where the ending pattern is included repeatedly. I.g. if you have "a.*c" and match "abbcbbcbbcbbc" against it, the match() method produces a stack overflow (not for strings this short, but starting for sizes of about some k already). I also had a second version of this problem where the match() method just crashes. The debugger steps in and never comes out again, but no exception is thrown. This happened with Visual Cafe 4.0 on an NT4 workstation.
Oh, I forgot: I had this problem with both regexp 1.1 and 1.2
I have come up with an Error using Regular Expression. A java.lang.StackOverflowError occuring at the line where i am trying to match an RE against some String. Please, help me. I'll be very thankfull to you. System: x86 OS: Red Hat Linux 7 Database: Sybase 11 Development Tool: JSP Regular Expression: jakarta-regexp-1.2 Code Snippet: try { ObjRegExpExt = new org.apache.regexp.RE(mstrDetailExtRegEx) ; // RE is provided below ObjRegExpExt.setMatchFlags(ObjRegExpExt.MATCH_CASEINDEPENDENT) ; } catch (Exception e) { System.out.println("Exception Rose: " + e.toString()); } // Match the RegExp boolean bMatched1= ObjRegExpExt.match(mstrHTMLSource) ; // This line is responsible for StackOverflowError Java Documentaion says that; public class StackOverflowError extends VirtualMachineError Thrown when a stack overflow occurs because an application recurses too deeply. RE(mstrDetailExtRegEx): <table border="0" cellspacing="0" cellpadding="5" align="center">(.*)<B>Silver Plan(.*)</B></FONT><br> String is (mstrHTMLSource): <!-- Begin Page Header --> <html><head><title>Unicard Travel Association Quote & Buy</title> <meta http-equiv="Content-Type" content="text/html; charset=iso- 8859-1"><script language="JavaScript"><!--function MM_swapImgRestore() { file://v2.0 if (document.MM_swapImgData != null) for (var i=0; i< (document.MM_swapImgData.length-1); i+=2) document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];}function MM_preloadImages() { file://v2.0 if (document.images) { var imgFiles = MM_preloadImages.arguments; if (document.preloadArray==null) document.preloadArray = new Array(); var i = document.preloadArray.length; with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){ preloadArray[i] = new Image; preloadArray[i++].src = imgFiles[j]; } }}function MM_swapImage () { file://v2.0 var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData; for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) { objStr = MM_swapImage.arguments [(navigator.appName == 'Netscape')?i:i+1]; if ((objStr.indexOf ('document.layers[')==0 && document.layers==null) || (objStr.indexOf ('document.all[') ==0 && document.all ==null)) objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length); obj = eval(objStr); if (obj != null) { swapArray[j++] = obj; swapArray [j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j]; obj.src = MM_swapImage.arguments[i+2]; } } document.MM_swapImgData = swapArray; file://used for restore}//--></script><SCRIPT LANGUAGE="JavaScript"> <!-- Hide script from old browsers sNav = new String(navigator.platform) vPltFrm = sNav.substring(0,3) if (vPltFrm != 'Mac') { document.write('<link rel=stylesheet href=bodytext.css>') } else { document.write('<link rel=stylesheet href=macbodytext.css>') } // End hiding from old browsers --> </script></head><body bgcolor="#FFFFFF" background="images/background2.gif" onLoad="MM_preloadImages ('images/bthl_home.gif','#945808464640');MM_preloadImages ('images/bthl_quote.gif','#945808555490');MM_preloadImages ('images/bthl_cost.gif','#945808610030');MM_preloadImages ('images/bthl_plan.gif','#945808632610');MM_preloadImages ('images/bthl_faq.gif','#945808663030');MM_preloadImages ('images/bthl_links.gif','#945808713460')"><BASEFONT SIZE="2" FACE="Arial, Helvetica, Sans-serif"><table width="600" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> <table width="600" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="8" width="508"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="images/bannernew.gif" width="508" height="56"></td> <td align="right"><a href="help.asp"><img src="images/click_for_help.gif" width="77" height="55" border="0"></a></td> </tr> </table> </td> </tr> <tr> <td width="125"><img src="images/side_graphic.gif" width="125"></td> <td width="46"><a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage ('document.Image4','document.Image4','images/bthl_home.gif','#945808464640')"><i mg name="Image4" border="0" src="images/bt_home.gif" width="46"></a></td> <td width="88"><a href="quote.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage ('document.Image5','document.Image5','images/bthl_quote.gif','#945808555490')">< img name="Image5" border="0" src="images/bt_quote.gif" width="88"></a></td> <td width="103"><a href="benefits/planbenefit.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage ('document.Image6','document.Image6','images/bthl_cost.gif','#945808610030')"><i mg name="Image6" border="0" src="images/bt_cost.gif" width="103"></a></td> <td width="10"><a href="benefits/plandetail.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage ('document.Image7','document.Image7','images/bthl_plan.gif','#945808632610')"><i mg name="Image7" border="0" src="images/bt_plan.gif" width="86"></a></td> <td width="37"><a href="faq.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage ('document.Image8','document.Image8','images/bthl_faq.gif','#945808663030')"><im g name="Image8" border="0" src="images/bt_faq.gif" width="37"></a></td> <td width="4"><a href="links/links.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage ('document.Image9','document.Image9','images/bthl_links.gif','#945808713460')">< img name="Image9" border="0" src="images/bt_links.gif" width="85"></a></td> <td width="30"> </td> </tr> </table> <p align="center"><font face="Arial, Helvetica, sans-serif" size="4" color="#000099"><b><span class="areaheader">Quote & Buy</span></b></font></p> <table border="0" cellspacing="0" cellpadding="5" align="center"> <tr> <td align="center"><FONT FACE="Arial, Halvetica, Sans-Serif" SIZE="2"><B>Silver Plan<br>US$835</B></FONT><br> <form action="https://www.unicard.com/purchase/buy1.asp" method="post"> <!-- <form action="http://localhost/unicard/purchase/buy1.asp" method="post">--> <INPUT TYPE="hidden" NAME="aff_id" VALUE="none"> <INPUT TYPE="hidden" NAME="travelers" VALUE="3"> <INPUT TYPE="hidden" NAME="length" VALUE="5"> <INPUT TYPE="hidden" NAME="family" VALUE="yes"> <INPUT TYPE="hidden" NAME="plantype" VALUE="s"> <input type="image" name="submit" src="images/buy_silver.gif" border="0" alt="Buy Silver Plan"> </FORM> </td> <td align="center"><FONT FACE="Arial, Halvetica, Sans-Serif" SIZE="2"><B>Gold Plan<br>US$1115</B></FONT><br> <form action="https://www.unicard.com/purchase/buy1.asp" method="post"> <INPUT TYPE="hidden" NAME="aff_id" VALUE="none"> <INPUT TYPE="hidden" NAME="travelers" VALUE="3"> <INPUT TYPE="hidden" NAME="length" VALUE="5"> <INPUT TYPE="hidden" NAME="family" VALUE="yes"> <INPUT TYPE="hidden" NAME="plantype" VALUE="g"> <input type="image" name="submit" src="images/buy_gold.gif" border="0" alt="Buy Gold Plan"> </FORM> </td> <td align="center"><FONT FACE="Arial, Halvetica, Sans- Serif" SIZE="2"><B>Platinum Plan<br>US$1230</B></FONT><br> <form action="https://www.unicard.com/purchase/buy1.asp" method="post"> <INPUT TYPE="hidden" NAME="aff_id" VALUE="none"> <INPUT TYPE="hidden" NAME="travelers" VALUE="3"> <INPUT TYPE="hidden" NAME="length" VALUE="5"> <INPUT TYPE="hidden" NAME="family" VALUE="yes"> <INPUT TYPE="hidden" NAME="plantype" VALUE="p"> <input type="image" name="submit" src="images/buy_platinum.gif" border="0" alt="Buy Platinum Plan"> </FORM> </td> </tr> <tr> <td colspan="3" align="center"><a href="benefits/planbenefit.html" target="new">Click here to review plan costs and benefits</a><br> <a href="http://www.xe.net/ucc" target="new">Click here to bring up a currency converter</a></td> </tr></table> <hr> <Form action="quote.asp" method="post"> <table border="0" cellspacing="0" cellpadding="3" align="center"> <tr> <td valign="top"><b><font face="Arial, Helvetica, sans-serif" size="2">Number of Travelers</font></b></td> <td valign="top" width=10 rowspan="6"> </td> <td valign="top"><font face="Arial, Helvetica, sans-serif" size="2"><b>Length of Membership</b></font></td> </tr> <tr> <td valign="top"> <select name="child"> <option value="0" selected>0</option> <option value="1" >1</option> <option value="2" >2</option> <option value="3" >3</option> <option value="4" >4</option> </select> <font face="Arial, Helvetica, sans-serif" size="2">Under Age 2</font> </td> <td valign="top"> <select name="length"> <option value="1" >5 Days</option> <option value="2" >17 Days</option> <option value="3" >24 Days</option> <option value="4" >31 Days</option> <option value="5" selected>Annual Plan</option> </select> </td> </tr> <tr> <td valign="top"> <select name="child1"> <option value="0" >0</option> <option value="1" selected>1</option> <option value="2" >2</option> <option value="3" >3</option> <option value="4" >4</option> </select> <font face="Arial, Helvetica, sans-serif" size="2">Ages 2 - 15</font> </td> <td valign="top"><b><font face="Arial, Helvetica, sans-serif" size="2">Is this a Family Plan?</font></b></td> </tr> <tr> <td valign="top"> <select name="adult"> <option value="0" >0</option> <option value="1" >1</option> <option value="2" selected>2</option> <option value="3" >3</option> <option value="4" >4</option> </select> <font face="Arial, Helvetica, sans-serif" size="2">Ages 16 - 64</font> </td> <td valign="top" rowspan="2"> <select name="family"> <option value="no" >No</option> <option value="yes" selected>Yes</option> </select><br> <font face="Arial, Helvetica, sans-serif" size="1" color="#990000"> <B>Family Plan is limited to 4 travelers</B><br> <b>Family plan is limited to parent(s) traveling</b><br> with dependent children age 23 or under.</b></font> </td> </tr> <tr> <td valign="top"> <select name="adult1"> <option value="0" selected>0</option> <option value="1" >1</option> <option value="2" >2</option> <option value="3" >3</option> <option value="4" >4</option> </select> <font face="Arial, Helvetica, sans-serif" size="2">Ages 65 - 74</font> </td> <!--<td valign="top"> </td>--> </tr> <tr> <td valign="top"> <select name="adult2"> <option value="0" selected>0</option> <option value="1" >1</option> <option value="2" >2</option> <option value="3" >3</option> <option value="4" >4</option> </select> <font face="Arial, Helvetica, sans-serif" size="2">Ages 75 - 84</font> </td> <td valign="top"><input type="Submit" name="quote" value="Get A Quote"></td> </tr> </table> </form><!-- Begin Page Footer --> <div align="center" class="sidemenu"> <p><br> <font size="1" face="Arial, Helvetica, sans-serif" color="#000099"> <a href="index.html">Home</a> | <a href="quote.asp">Quote & Buy</a> | <a href="benefits/planbenefit.html">Cost & Benefits</a> | <a href="benefits/plandetail.html">Plan Details</a> | <a href="faq.html">FAQ</a> | <a href="links/links.html">Links</a> <br> <a href="help.asp">Help</a> | <a href="https://www.unicard.com/members/members.html">Member Services</a> | <a href="affiliates/index.html">Affiliates</a> | <a href="privacy.html"> Privacy Statement</a></font></p> <p><font face="Arial, Helvetica, sans- serif" size="1">© Copyright 1999, Unicard Travel Association</font></p> </div> </td> </tr></table></body></html><!-- Copyright 1999 Insuractive --> regards, Ahmed Shaikh
I found a workaround for my particular situation ... When using the following logic: //Match ASCII 32 through ASCII 127, plus ASCII 10 and ASCII 13 String DEFAULT_KEYBOARD_FILTER = "^[\\x20-\\x7F\\x0A\\x0D]*$"; RE regExp = new RE(DEFAULT_KEYBOARD_FILTER); //if it DOESN'T match, then throw if(!regExp.match(testVal)) throw new FieldValidationException(fieldNamePretty + " can not contain special characters."); i would recive a StackOverflowError with a string of 2 or 3 kilobytes ... However, by using the inverse expression logic: String DEFAULT_KEYBOARD_FILTER = "[^\\x20-\\x7F\\x0A\\x0D]"; //if it DOES match, then throw if(regExp.match(testVal)) throw new FieldValidationException(fieldNamePretty + " can not contain special characters."); everything went smoothly ... so ... that's my 2 cents .. :)
I am using the RE class in Sybases Jaguar product and it works fine in Windows 2000, but throws a StackOverflowError (in RE.matchNode(String search, int i)) when running the same code against the same data in Sybase Jaguar on Solaris 2.7. Some tests scenarios work on both 2000 and Solaris while others never work on Solaris but always work on 2000.
The regular expression matcher is recursive so the more work it has to do the larger the stack required. Possible solutions to this problem (for the user): 1) Tune the regular expression esp removing alternations where possible. 2) Give the JVM more stack space. 3) Use smaller data sets. There may be ways of optimising the matcher to no use so much stack space but that requires major refactoring.
*** Bug 18741 has been marked as a duplicate of this bug. ***
*** Bug 18616 has been marked as a duplicate of this bug. ***
*** Bug 16536 has been marked as a duplicate of this bug. ***
*** Bug 21469 has been marked as a duplicate of this bug. ***
*** Bug 24770 has been marked as a duplicate of this bug. ***
*** Bug 35834 has been marked as a duplicate of this bug. ***