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.

View | Details | Raw Unified | Return to bug 159125
Collapse All | Expand All

(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/highlighting/CompoundHighlightsContainer.java (-3 / +51 lines)
Lines 287-293 Link Here
287
        }
287
        }
288
    }
288
    }
289
289
290
    private void updateCache(int startOffset, int endOffset, OffsetsBag bag) {
290
    private void updateCache(final int startOffset, final int endOffset, OffsetsBag bag) {
291
        if (LOG.isLoggable(Level.FINE)) {
291
        if (LOG.isLoggable(Level.FINE)) {
292
            LOG.fine("Updating cache: <" + startOffset + ", " + endOffset + ">"); //NOI18N
292
            LOG.fine("Updating cache: <" + startOffset + ", " + endOffset + ">"); //NOI18N
293
        }
293
        }
Lines 298-305 Link Here
298
            }
298
            }
299
299
300
            try {
300
            try {
301
                HighlightsSequence seq = layers[i].getHighlights(startOffset, endOffset);
301
                final HighlightsSequence seq = layers[i].getHighlights(startOffset, endOffset);
302
                bag.addAllHighlights(seq);
302
                final int layerIndex = i; //saving this so we can debug corrupt layers (aka the ones that need clipping)
303
                final HighlightsContainer currentLayerObject = layers[i];
304
                bag.addAllHighlights(new HighlightsSequence() {
305
306
                    int start = -1, end = -1;
307
                    public boolean moveNext() {
308
                        boolean hasNext = seq.moveNext();
309
                        //XXX: the problem here is if the sequence we are wrapping is sorted by startOffset.
310
                        // In practice I think it is, but I cannot afford to make that assumption now.
311
                        // So I have to check both boundaries, not only start and end offset separately.
312
                        boolean retry = hasNext;
313
                        while(retry){
314
                            start = seq.getStartOffset();
315
                            end = seq.getEndOffset();
316
                            assert start <=end : "Start should come before the end offset in the sequence";
317
318
                            if (start > endOffset || end < startOffset) {
319
                                //this highlight is totally outside our rage, there is nothing we can clip, we must retry
320
                                LOG.warning("Corrupt layer found (#" + layerIndex + ":" + currentLayerObject + "). Start offset " + start + " and end offset "+end+" are outside the range [" + startOffset + "," + endOffset+"], skipping.");
321
                                retry = hasNext = seq.moveNext();
322
                            }else{
323
                                retry = false;
324
                            }
325
                        }
326
                        if(hasNext){
327
                            if (start < startOffset) {
328
                                LOG.warning("Corrupt layer found (#" + layerIndex + ":" + currentLayerObject + "). Start offset " + start + " should be >=" + startOffset + ". Clipping...");
329
                                start = startOffset;
330
                            }
331
                            if (end > endOffset) {
332
                                LOG.warning("Corrupt layer found (#" + layerIndex + ":" + currentLayerObject + "). End offset " + end + " should be <=" + endOffset + ". Clipping...");
333
                                end = endOffset;
334
                            }
335
                        }
336
                        return hasNext;
337
                    }
338
339
                    public int getStartOffset() {
340
                        return start;
341
                    }
342
343
                    public int getEndOffset() {
344
                        return end;
345
                    }
346
347
                    public AttributeSet getAttributes() {
348
                        return seq.getAttributes();
349
                    }
350
                });
303
                if (LOG.isLoggable(Level.FINE)) {
351
                if (LOG.isLoggable(Level.FINE)) {
304
                    LOG.fine(dumpLayerHighlights(layers[i], startOffset, endOffset));
352
                    LOG.fine(dumpLayerHighlights(layers[i], startOffset, endOffset));
305
                }
353
                }

Return to bug 159125