This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 131514 - javax.swing.text.BadLocationException: Invalid offset=3574 not within <0, 3573>
Summary: javax.swing.text.BadLocationException: Invalid offset=3574 not within <0, 3573>
Status: CLOSED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: HTML Editor (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker with 1 vote (vote)
Assignee: Marek Fukala
URL: http://statistics.netbeans.org/except...
Keywords:
: 131800 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-03-29 10:06 UTC by carentrica
Modified: 2009-05-18 10:47 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 40353


Attachments
stacktrace (1.64 KB, text/plain)
2008-03-30 21:26 UTC, Jan Lahoda
Details
stacktrace (1.64 KB, text/plain)
2008-03-31 09:19 UTC, kawazu428
Details
stacktrace (1.64 KB, text/plain)
2008-03-31 15:38 UTC, Miloslav Metelka
Details
stacktrace (1.64 KB, text/plain)
2008-03-31 19:01 UTC, jpleed3
Details
stacktrace (1.64 KB, text/plain)
2008-04-01 19:28 UTC, Jindrich Sedek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description carentrica 2008-03-29 10:06:34 UTC
Build: NetBeans IDE Dev (Build 200803240003)
VM: Java HotSpot(TM) Client VM, 1.6.0_02-b06, Java(TM) SE Runtime Environment, 1.6.0_02-b06
OS: Windows XP, 5.1, x86
User comments: Was not doing anythign special, just editing code in the main NB window	
while editing code
STACKTRACE: (first 10 lines)
javax.swing.text.BadLocationException: Invalid offset=3574 not within <0, 3573>
        at org.netbeans.editor.Utilities.checkOffsetValid(Utilities.java:1331)
        at org.netbeans.editor.Utilities.getLineOffset(Utilities.java:613)
        at org.netbeans.modules.html.editor.gsf.HtmlStructureScanner$1.visit(HtmlStructureScanner.java:120)
        at org.netbeans.editor.ext.html.parser.AstNodeUtils.visitChildren(AstNodeUtils.java:90)
        at org.netbeans.editor.ext.html.parser.AstNodeUtils.visitChildren(AstNodeUtils.java:91)
        at org.netbeans.modules.html.editor.gsf.HtmlStructureScanner.folds(HtmlStructureScanner.java:131)
        at org.netbeans.modules.gsfret.editor.fold.GsfFoldManager$JavaElementFoldTask.addTree(GsfFoldManager.java:403)
        at org.netbeans.modules.gsfret.editor.fold.GsfFoldManager$JavaElementFoldTask.scan(GsfFoldManager.java:396)
        at org.netbeans.modules.gsfret.editor.fold.GsfFoldManager$JavaElementFoldTask.gsfFoldScan
(GsfFoldManager.java:320)
        at org.netbeans.modules.gsfret.editor.fold.GsfFoldManager$JavaElementFoldTask.run(GsfFoldManager.java:287)
Comment 1 carentrica 2008-03-29 10:08:28 UTC
This error is perpetual. Loading existing projects or doing ANY editing at all. The IDE is totally unusable!!!!
Comment 2 Exceptions Reporter 2008-03-29 16:27:58 UTC
This issue has already 5 duplicates 
Comment 3 Jan Lahoda 2008-03-30 21:26:24 UTC
Build: NetBeans IDE Dev (Build 080329)
VM: Java HotSpot(TM) Client VM, 11.0-b11, Java(TM) SE Runtime Environment, 1.6.0_10-beta-b14
OS: Linux, 2.6.20-16-generic, i386

User Comments: 
Opening a JSP file.
Comment 4 Jan Lahoda 2008-03-30 21:26:27 UTC
Created attachment 59370 [details]
stacktrace
Comment 5 kawazu428 2008-03-31 09:19:20 UTC
Build: NetBeans IDE Dev (Build 200803302302)
VM: Java HotSpot(TM) Client VM, 11.0-b11, Java(TM) SE Runtime Environment, 1.6.0_10-beta-b13
OS: Linux, 2.6.24-ARCH, i386

User Comments: 
editing jsp file?
Comment 6 kawazu428 2008-03-31 09:19:24 UTC
Created attachment 59385 [details]
stacktrace
Comment 7 Miloslav Metelka 2008-03-31 15:38:25 UTC
Build: NetBeans IDE Dev (Build 080330)
VM: Java HotSpot(TM) Client VM, 1.6.0_03-b04, Java(TM) SE Runtime Environment, 1.6.0_03-b04
OS: Linux, 2.6.22-14-generic, i386

User Comments: 
Typing in javascript section of jsp attached in issue http://www.netbeans.org/issues/show_bug.cgi?id=129561
Comment 8 Miloslav Metelka 2008-03-31 15:38:29 UTC
Created attachment 59414 [details]
stacktrace
Comment 9 jpleed3 2008-03-31 19:01:21 UTC
Build: NetBeans IDE Dev (Build 200803302302)
VM: Java HotSpot(TM) Client VM, 1.6.0_02-b06, Java(TM) SE Runtime Environment, 1.6.0_02-b06
OS: Windows XP, 5.1, x86

User Comments: 
Comment 10 jpleed3 2008-03-31 19:01:32 UTC
Created attachment 59438 [details]
stacktrace
Comment 11 kawazu428 2008-04-01 08:49:27 UTC
Right now this does reproducibly appear every time I try using code completion within a JSP file, practically rendering
the JSP editor in current build (200804010004) unusable. Seems more than just a P3 to me.
Comment 12 Jindrich Sedek 2008-04-01 19:28:37 UTC
Build: NetBeans IDE Dev (Build 200803311426)
VM: Java HotSpot(TM) Client VM, 1.6.0_10-ea-b07, Java(TM) SE Runtime Environment, 1.6.0_10-ea-b07
OS: SunOS, 5.11, x86

User Comments: 
[web/jsp editor]
Create new JSP file
insert this code inside:
--------------------------
<html>
    <body bgcolor="white">
        
        <h1>
            I have been invoked by
            <% out.print(request.getAttribute("servletName").toString());%>
            Servlet.
        </h1>
    </body>
</html>
-------------
BLE is thrown
Comment 13 Jindrich Sedek 2008-04-01 19:28:47 UTC
Created attachment 59507 [details]
stacktrace
Comment 14 Marek Fukala 2008-04-01 19:45:19 UTC
It looks like there a two problems in the HtmlStructureScanner.

One is that the document is not readlocked during the AST visiting due to performance reasons. However I need to touch
the document to find line starts/ends. If there is not html virtual translated source (editing pure html) it may happen
that during the ast visiting the document is modified and then the offsets may go beyond end of the document. 

Second problem is the BLE for -1 position - this looks like no document position has been found for a position in
virtual source. This is bad, I need to investigate it more.

Anyway, I think this issue must be fixed in 6.1, priority is already P1 so just setting milestone to dev. I try to fix asap.
Comment 15 kawazu428 2008-04-01 21:16:26 UTC
Can you reproduce the BLE for -1 position issue? Do you require any more information / examples on how and when this is
likely to happen?
Comment 16 davideconsonni 2008-04-01 23:05:14 UTC
here my jsp
javax.swing.text.BadLocationException: Invalid offset=-1 not within <0, 4600>
---------8<----------------------
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<fmt:setBundle basename="it.codd_date.r_c_s.newssearch.nl.ARCS_MG_SEARCH_PRESSAREA_CENTER" />

<%String tableWidth = "width=\"500\"";%>
<form method="POST" action="<portlet:actionURL/>">   

<%-- search criteria  --%>
<table <%=tableWidth%>>
    <tr>
<td><fmt:message key='label_find' /></td>
<td><input type="text" name="find" id="<portlet:namespace/>find" value="<c:out value="${ARCS_MG_SEARCH_find}"/>"/></td>
<td width="50%"></td>
<td nowrap>
    <input type="checkbox" value="Y" name="onlytitle" id="<portlet:namespace/>onlytitle" <c:out
value="${ARCS_MG_SEARCH_onlytitle=='Y' ? 'CHECKED' : ''}"/>>
           <label for="<portlet:namespace/>onlytitle"><fmt:message key='label_onlytitle' /></label>                
</td>
<td nowrap>
    <input type="checkbox" value="Y" name="pricesensitive" id="<portlet:namespace/>pricesensitive" <c:out
value="${ARCS_MG_SEARCH_pricesensitive=='Y' ? 'CHECKED' : ''}"/>>
           <label for="<portlet:namespace/>pricesensitive"><fmt:message key='label_pricesensitive' /></label>          
     
</td>    
</tr>
</table>
<table <%=tableWidth%>>
    <tr>
    <td><fmt:message key='label_month' /></td>
    <td>
        <select name="month" id="<portlet:namespace/>month">
        <c:forEach var="month" items="${ARCS_MG_SEARCH_list_months}">
            <option value="<c:out value="${month}"/>"  <c:out value="${month == ARCS_MG_SEARCH_list_months_SELECTED ?
'SELECTED' : ''}"/>><c:out value="${month}"/>
                </c:forEach>
                </select>                    
    </td>
    <td><fmt:message key='label_year' /></td>
    <td>
        <select name="year" id="<portlet:namespace/>year">
        <c:forEach var="year" items="${ARCS_MG_SEARCH_list_years}">
            <option value="<c:out value="${year}"/>"  <c:out value="${year == ARCS_MG_SEARCH_list_years_SELECTED ?
'SELECTED' : ''}"/>><c:out value="${year}"/>
                </c:forEach>
                </select>                
    </td>
    <td width="50%"></td>
    <td><input type="submit" value="<fmt:message key='label_button_find' />"/></td>
    </tr>
</table>

<%-- navigation --%>
<table <%=tableWidth%>>
    <tr>
    <td align="left"><span><b>18 risultati</b> rilevati per <b><c:out value="${ARCS_MG_SEARCH_find}"/></b></span></td>
    <td align="right"><span>|<<  < Pagina 4/10 > >>|</span></td>
    </tr>
</table>

<%-- results --%>
<table <%=tableWidth%>>
    <tr><td><span>&nbsp;</span></td></tr>
    <tr><td style="background-color: #F3F8FC; border-top: 1px solid #DDD;"><span style="color: #007ECB;"> 16 settembre
2007- h 21:30 </span> <img src="<c:url value="/img/pricesensitive.gif"/>"></td></tr>
    <tr><td><span style="color: #000;"><b>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec diam nibh,
dictum fringilla, ultricies in, laoreet ut, ante. Mauris interdum orci in urna. Aenean in magna. Nunc feugiat tempor
lectus. Phasellus tortor nulla, lacinia a, placerat non, feugiat non, metus.</b></span></td></tr>
    <tr><td><span> Download</span> <img src="<c:url value="/img/pdf.gif"/>"></td></tr>
    
    <tr><td><span>&nbsp;</span></td></tr>
    <tr><td style="background-color: #F3F8FC; border-top: 1px solid #DDD;"><span style="color: #007ECB;">  27 giugno
2007 </span> <img src="<c:url value="/img/pricesensitive.gif"/>"></td></tr>
    <tr><td><span style="color: #000;"><b>Suspendisse consectetuer. Etiam tempor tristique sem. Nunc semper pellentesque
mi. Aenean eu metus. Suspendisse potenti. Nam gravida dolor vel nibh. Aenean dolor. Integer egestas, ipsum a sagittis
viverra, nunc odio dapibus felis, id pharetra odio metus nec sapien. Sed dictum.</b></span></td></tr>
    <tr><td><span> Download</span> <img src="<c:url value="/img/pdf.gif"/>"></td></tr>
    
    <tr><td><span>&nbsp;</span></td></tr>
    <tr><td style="background-color: #F3F8FC; border-top: 1px solid #DDD;"><span style="color: #007ECB;"> 16 ottobre
2008- h 21:30 </span> <img src="<c:url value="/img/pricesensitive.gif"/>"></td></tr>
    <tr><td><span style="color: #000;"><b>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec diam nibh,
dictum fringilla, ultricies in, laoreet ut, ante. Mauris interdum orci in urna. Aenean in magna. Nunc feugiat tempor
lectus. Phasellus tortor nulla, lacinia a, placerat non, feugiat non, metus.</b></span></td></tr>
    <tr><td><span> Download</span> <img src="<c:url value="/img/pdf.gif"/>"></td></tr>    
</table>

</form>
---------8<----------------------
Comment 17 davideconsonni 2008-04-01 23:12:40 UTC
and my nb version is

Product Version: NetBeans IDE Dev (Build 080401)
Java: 1.6.0_02; Java HotSpot(TM) Client VM 1.6.0_02-b05
System: Linux version 2.6.24.2-smp running on i386; ISO-8859-1; en_US (nb)
Comment 18 davideconsonni 2008-04-02 13:32:27 UTC
this issue is similar to 130009 isn't it ?
Comment 19 Marek Fukala 2008-04-02 16:00:35 UTC
Thanks for the file to reproduce the BLE -1 problem. It will help me a lot.
Comment 20 Marek Fukala 2008-04-02 16:20:19 UTC
*** Issue 131800 has been marked as a duplicate of this issue. ***
Comment 21 Marek Fukala 2008-04-02 17:23:16 UTC
The problem of -1 offset passed to the  Utilities.getLineOffset() fixed in HtmlModel in main in revision 7a389aaba281.

As for the offset > doc.getLength() - my previous conclusion was quite rushy - the document is readlocked during the ast
visiting but I am not sure if is readlocked between parsing and calling the StructureScanner. It looks like it isn't. So
I switched the exception report in such case to INFO level to not to bother users, but be able to track it if the
problem is somewhere else. I guess it will not be happening so often.

QE please verify, the fix may affect features based on AST like navigator, braces matching, semantic highl., folding and
error reporting. OTOH it is quite simple and straightforward so I belive just quick sanity testing is enought.
Comment 22 davideconsonni 2008-04-02 19:53:50 UTC
Product Version: NetBeans IDE Dev (Build 080402)
Java: 1.6.0_02; Java HotSpot(TM) Client VM 1.6.0_02-b05
System: Linux version 2.6.24.2-smp running on i386; ISO-8859-1; en_US (nb)

and no more exception, thanks :)
Comment 23 Jindrich Sedek 2008-04-03 08:32:01 UTC
I don't see any regression after this fix in main. Please merge it into 6.1 clone.
Comment 24 Marek Fukala 2008-04-03 23:14:40 UTC
marking as fixed (in main)
Comment 25 Marek Fukala 2008-04-03 23:48:00 UTC
fixed in release61 clone in revision decadf420b1b
Comment 26 Martin Schovanek 2008-04-04 14:56:04 UTC
Verified in relese61.