Bug 532557 - BadLocationException below ConsoleDocument.getLineOfOffset (thrown in ListLineTracker.getLineNumberOfOffset)
Summary: BadLocationException below ConsoleDocument.getLineOfOffset (thrown in ListLin...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 399638 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-03-16 18:23 EDT by EPP Error Reports CLA
Modified: 2024-01-29 20:33 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description EPP Error Reports CLA 2018-03-16 18:23:38 EDT
The following problem was reported via the automated error reporting:

Message: HIDDEN
org.eclipse.jface.text.BadLocationException: null
    at org.eclipse.jface.text.ListLineTracker.getLineNumberOfOffset(ListLineTracker.java:136)
    at org.eclipse.jface.text.AbstractLineTracker.getLineNumberOfOffset(AbstractLineTracker.java:151)
    at org.eclipse.jface.text.AbstractDocument.getLineOfOffset(AbstractDocument.java:867)
    at org.eclipse.ui.internal.console.ConsoleDocument.getLineOfOffset(ConsoleDocument.java:78)
    at org.eclipse.ui.internal.console.ConsolePatternMatcher$MatchJob.run(ConsolePatternMatcher.java:117)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


The reporter(s) left the following comment(s):

--- Anonymous wrote on 1d86: ---
Paste from clipboard failed (Caps locked)

It just happened nothing and the content appeared in the stack trace console instead.

--- Anonymous wrote on 9cd1: ---
I ran a JUnit-test and and opened a failed test. Then I clicked on "Show Stack Trace in Console View".

Bundles:
| org.eclipse.core.jobs | 3.7.0.v20150330-2103 | 3.10.0.v20171130-1004 |
| org.eclipse.jface.text | 3.10.0.v20150603-1752 | 3.13.0.v20171130-2251 |
| org.eclipse.ui.console | 3.6.100.v20150822-1912 | 3.7.100.v20171201-0724 |

Operating Systems:
| Linux | 2.6.32.15 | 4.15.1 |
| MacOSX | 10.9.5 | 10.13.3 |
| Windows | 6.1.0 | 10.0.0 |


The above information is a snapshot of the collected data. Visit https://dev.eclipse.org/recommenders/committers/aeri/v2/#!/problems/5786281ae4b0b5f63da6b71f for the latest data.

Thank you for your assistance.
 Your friendly error-reports-inbox.
Comment 1 Andrey Loskutov CLA 2018-03-16 18:24:40 EDT
I see it usually first time I open console from the error log view.

Just happened again:
eclipse.buildId=4.8.0.I20180316-0740
java.version=1.8.0_162
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=de_DE
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -data file:/C:/workspaces/platform/

org.eclipse.ui.console
Error
Fri Mar 16 23:18:08 CET 2018
Error logged from Console plug-in:

org.eclipse.jface.text.BadLocationException
	at org.eclipse.jface.text.ListLineTracker.getLineNumberOfOffset(ListLineTracker.java:136)
	at org.eclipse.jface.text.AbstractLineTracker.getLineNumberOfOffset(AbstractLineTracker.java:151)
	at org.eclipse.jface.text.AbstractDocument.getLineOfOffset(AbstractDocument.java:868)
	at org.eclipse.ui.internal.console.ConsoleDocument.getLineOfOffset(ConsoleDocument.java:78)
	at org.eclipse.ui.internal.console.ConsolePatternMatcher$MatchJob.run(ConsolePatternMatcher.java:119)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)
Comment 2 Eclipse Genie CLA 2018-03-16 18:46:27 EDT
New Gerrit change created: https://git.eclipse.org/r/119606
Comment 4 Andrey Loskutov CLA 2018-03-17 13:41:05 EDT
(In reply to Eclipse Genie from comment #2)
> New Gerrit change created: https://git.eclipse.org/r/119606

Just adding some more context to the exception.
Comment 5 Andrey Loskutov CLA 2019-02-04 02:54:50 EST
*** Bug 399638 has been marked as a duplicate of this bug. ***
Comment 6 Andrey Loskutov CLA 2019-02-04 03:09:52 EST
Just got it again on 4.11 head.

org.eclipse.jface.text.BadLocationException: Offset > length: 873 > 831
at org.eclipse.jface.text.ListLineTracker.getLineNumberOfOffset(ListLineTracker.java:141)
at org.eclipse.jface.text.AbstractLineTracker.getLineNumberOfOffset(AbstractLineTracker.java:154)
at org.eclipse.jface.text.AbstractDocument.getLineOfOffset(AbstractDocument.java:871)
at org.eclipse.ui.internal.console.ConsoleDocument.getLineOfOffset(ConsoleDocument.java:81)
at org.eclipse.ui.internal.console.ConsolePatternMatcher$MatchJob.run(ConsolePatternMatcher.java:117)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

See also bug 334280 comment 2: it talks about missing synchronization in SynchronizableDocument.getLineOfOffset. 

We *also* have not synchronized access in ConsoleDocument.getLineOfOffset(int) (but we are not instance of SynchronizableDocument) - the only method in the class which is not synchronized!!! The synchronization was removed via bug 132398 comment 3 for performance reasons.

Since ConsolePatternMatcher$MatchJob is not running in UI thread, it simply misses the updates done to the console document in UI thread.

In the particular case of opening console for a given error I think we can do a small fix (without touching synchronization): in JavaStackTraceConsoleFactory.openConsole(String) we should NOT open console + init document unconditionally, but init only if there is no string to set as document. I will push a patch in a moment.
Comment 7 Andrey Loskutov CLA 2019-02-04 03:33:15 EST
See also bug 478020 comment 2: on Windows I see an error at different exception an different code (StyledTextRenderer.textChanging) for the same action (open java console for an error in the error log view), but also there was an assumption that ConsoleDocumentAdapter.getLineAtOffset(int) doesn't work reliably.

Interestingly, ConsoleDocumentAdapter.getLineAtOffset(int) does NOT use ConsoleDocument.getLineOfOffset(int) but implements its own lookup based on internal data (which is probably out-of-sync with the document).
Comment 8 Eclipse Genie CLA 2019-02-04 10:29:07 EST
New Gerrit change created: https://git.eclipse.org/r/136242
Comment 10 Eclipse Genie CLA 2019-05-01 17:55:31 EDT
New Gerrit change created: https://git.eclipse.org/r/141485
Comment 11 Eclipse Genie CLA 2019-05-01 18:04:28 EDT
New Gerrit change created: https://git.eclipse.org/r/141487
Comment 12 Paul Pazderski CLA 2019-05-01 18:06:53 EDT
This problem is not limited to the unsynchronized getLineOfOffset but to all document methods. The problem raise because MatchJob reads document length when it starts and than matches till its end. If document is changed meanwhile it may happen that MatchJob tries to match document parts which not exist anymore. There is some code which should handle such situations but fails in various cases.

(In reply to Eclipse Genie from comment #10)
> New Gerrit change created: https://git.eclipse.org/r/141485

I've created a test for this original problem with JavaStackTraceConsole initialization. It succeeds since your workaround for JavaStackTraceConsole works.

(In reply to Eclipse Genie from comment #11)
> New Gerrit change created: https://git.eclipse.org/r/141487

This test triggers the underlying problem with a simple TestConsole. Additional it includes a draft patch which synchronizes access to getLineOfOffset and stops MatchJob before document changes. It works quite good but since I learned more after my first work on this bug I'm quite sure it will break the console line tracker.

In general it is quite hard to actual experience this bug (maybe apart from the original problem). In JavaStackTraceConsole I managed to trigger it after some tries by pasting a huge stack trace and immediately clearing the console.
For IOConsole it may almost impossible to experience this bug. Typically the console document only grows which is unproblematic. The clear for IOConsole is performed by the trim job and the trim job does not run in concurrent with MatchJob due to job scheduling rules. So the only possibility to shrink the console document while MatchJob is running is user input and I think it is almost impossible a user removes enough input at the right moment to trigger an exception in MatchJob.
Comment 13 Eclipse Genie CLA 2022-02-07 11:16:42 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 14 Eclipse Genie CLA 2024-01-29 20:33:04 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.