Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/pro#2860 Fix NPE on sql text editing #33403

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.jkiss.dbeaver.model.sql.semantics;

import org.jkiss.code.Nullable;

import java.util.Iterator;
import java.util.Set;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -410,6 +412,7 @@ public NodesIterator<T> nodesIteratorAt(int position) {
NodeAndParentAtOffset<T> initialLocation = this.findImpl(position);
return switch (this.size) {
case 0 -> new NodesIterator<T>() {
@Nullable
@Override
public T getCurrValue() {
return null;
Expand All @@ -433,7 +436,9 @@ public boolean next() {
case 1 -> new NodesIterator<T>() {
boolean beforeFirst = position < OffsetKeyedTreeMap.this.root.offset;
boolean afterLast = position > OffsetKeyedTreeMap.this.root.offset;
Node<T> theOnlyNode = OffsetKeyedTreeMap.this.root;
final Node<T> theOnlyNode = OffsetKeyedTreeMap.this.root;

@Nullable
@Override
public T getCurrValue() {
return !this.beforeFirst && !this.afterLast ? this.theOnlyNode.content : null;
Expand Down Expand Up @@ -479,6 +484,7 @@ public boolean next() {
initialLocation.node.isSentinel() ? position : position - initialLocation.node.offset
);

@Nullable
@Override
public T getCurrValue() {
return this.currentLocation.node == null ? null : this.currentLocation.node.content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public IRegion applyDelta(int offset, int oldLength, int newLength) {
keyOffsetsToRemove = ListNode.push(keyOffsetsToRemove, currOffset);
this.forEachListener(l -> l.onScriptItemInvalidated(currItem));
lastAffectedOffset = currOffset + currItem.length();
} else if (it.prev()) {
} else if (it.prev() && it.getCurrValue() != null) {
currOffset = it.getCurrOffset();
SQLDocumentScriptItemSyntaxContext currItem2 = it.getCurrValue();
if (currOffset <= offset && currOffset + currItem2.length() > offset) {
Expand All @@ -218,7 +218,7 @@ public IRegion applyDelta(int offset, int oldLength, int newLength) {
} else {
lastAffectedOffset = offset + oldLength;
}
while (it.next() && (delta < 0 || lastAffectedOffset <= (offset + oldLength))) {
while (it.next() && it.getCurrValue() != null && (delta < 0 || lastAffectedOffset <= (offset + oldLength))) {
currOffset = it.getCurrOffset();
SQLDocumentScriptItemSyntaxContext currItem3 = it.getCurrValue();
keyOffsetsToRemove = ListNode.push(keyOffsetsToRemove, currOffset);
Expand Down Expand Up @@ -249,7 +249,7 @@ public IRegion applyDelta(int offset, int oldLength, int newLength) {
affectedRegion = new Region(scriptItem.offset, scriptItem.item.length());
} else {
NodesIterator<SQLDocumentScriptItemSyntaxContext> it = this.scriptItems.nodesIteratorAt(offset);
int start = it.prev() ? it.getCurrOffset() + it.getCurrValue().length() : 0;
int start = it.prev() && it.getCurrValue() != null ? it.getCurrOffset() + it.getCurrValue().length() : 0;
int length = it.next() ? (it.getCurrOffset() - start) : Integer.MAX_VALUE;
affectedRegion = new Region(start, length);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ public Interval dropInvisibleScriptItems(@NotNull Interval actualFragment) {
keyOffsetsToRemove = ListNode.push(keyOffsetsToRemove, off1);
this.forEachListener(l -> l.onScriptItemInvalidated(it1.getCurrValue()));
}
while (it1.next() && (off1 = it1.getCurrOffset()) + it1.getCurrValue().length() < rangeStart) {
while (it1.next() && it1.getCurrValue() != null && (off1 = it1.getCurrOffset()) + it1.getCurrValue().length() < rangeStart) {
keyOffsetsToRemove = ListNode.push(keyOffsetsToRemove, off1);
this.forEachListener(l -> l.onScriptItemInvalidated(it1.getCurrValue()));
}
Expand All @@ -301,7 +301,7 @@ public Interval dropInvisibleScriptItems(@NotNull Interval actualFragment) {
keyOffsetsToRemove = ListNode.push(keyOffsetsToRemove, off2);
this.forEachListener(l -> l.onScriptItemInvalidated(it2.getCurrValue()));
}
while (it2.prev() && (off2 = it2.getCurrOffset()) > rangeEnd) {
while (it2.prev() && it2.getCurrValue() != null && (off2 = it2.getCurrOffset()) > rangeEnd) {
keyOffsetsToRemove = ListNode.push(keyOffsetsToRemove, off2);
this.forEachListener(l -> l.onScriptItemInvalidated(it2.getCurrValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jkiss.dbeaver.model.lsm.test;

import org.antlr.v4.runtime.misc.Interval;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.sql.semantics.OffsetKeyedTreeMap;
import org.jkiss.dbeaver.model.stm.STMUtils;
import org.junit.Assert;
Expand Down Expand Up @@ -267,6 +268,7 @@ public int getCurrOffset() {
}
}

@Nullable
@Override
public T getCurrValue() {
return this.index >= 0 && this.index < list.size() ? list.get(this.index).data : null;
Expand Down