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.
I found this bug while looking for the issue reported in #159122 . Basically it is possible to have layers in the CompoundHighlightsContainer that are "broken" in various ways, which leads to corrupted coloring into the editor. One of them is the fact that the sequence returned by getHighlights(int, int) must be clipped. According to the HighlightsContainer.getHighlights javadoc: "any highlights outside of this range will be clipped by the rendering infrastructure". The problem is that this isn't respected by CompoundHighlightsContainer. More to the point the HighlightsSequence returned by the layers in updateCache(...) is added "as-is" to the OffsetsBag. This can lead to subtle repaint problems (like the one reported in #159122) where a broken layer can change the OffsetsBag *outside* the [startOffset,endOffset] area, because there is no boundary check for this. See the attached patch which fixes this by clipping to the boundary if a broken HighlightsSequence is detected.
Created attachment 77345 [details] CompoundHighlightsContainer.updateCache patch to have proper clipping
Created attachment 78126 [details] New patch that has better checks.
Just wanted to comment on the updated patch: I noticed situations where the returned highlights are totally outside the [startOffset, endOffset] range so I need to check for that too. Also, I'm not certain the HighlightsSequence is sorted by the start offset (though I assume it is?) so in my code I have to loop over the underlying sequence.
The patch has been applied to repo jet-main as changeset : 128933:eafd5f2c2766. Thanks for the contribution.
With Emilian's patch in I discovered a problem in SyntaxHighlighting layer, which in some situations supplied unclipped highlights or even highlights that were completely outside of the requested range. This should hopefully be remedied by http://hg.netbeans.org/jet-main/rev/9e5cf598425d