Skip to content

Commit 4580cfb

Browse files
committed
fix: java.lang.NullPointerException: Cannot invoke "java.util.List.add(Object)" because "this.myUncommittedActions" is null
1 parent 78ae35b commit 4580cfb

File tree

7 files changed

+14
-50
lines changed

7 files changed

+14
-50
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Nov 11, 2022
33

44
FIX: cannot init component state (componentName=CsvFileAttributes) #359
5+
FIX: cannot invoke "java.util.List.add(Object)" because "this.myUncommittedActions" is null #361
56
FIX: image in plugin description
67
FIX: plugin update restart
78

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ PS: The previous versions are still available on the project page.
110110
Update 3.0.1
111111
112112
FIX: cannot init component state (componentName=CsvFileAttributes) #359
113+
FIX: cannot invoke "java.util.List.add(Object)" because "this.myUncommittedActions" is null #361
113114
FIX: image in plugin description
114115
FIX: plugin update restart
115116

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/CsvTableModelBase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ public class CsvTableModelBase<T extends PsiFileHolder> implements CsvTableModel
2525
private int myCachedColumnCount = -1;
2626
private CsvEscapeCharacter myCachedEscapeCharacter;
2727
private Boolean myCachedHasErrors = null;
28-
2928
private int myPointedRow = -1;
3029
private PsiElement myPointedRecord = null;
31-
3230
private final CsvPsiTreeUpdater myPsiTreeUpdater;
3331

3432
private final PsiTreeChangeListener myPsiTreeChangeListener = new PsiTreeAnyChangeAbstractAdapter() {
@@ -52,8 +50,8 @@ public T getPsiFileHolder() {
5250
@Override
5351
public void dispose() {
5452
CsvTableModel.super.dispose();
55-
getPsiFile().getManager().removePsiTreeChangeListener(myPsiTreeChangeListener);
5653
myPsiTreeUpdater.dispose();
54+
getPsiFile().getManager().removePsiTreeChangeListener(myPsiTreeChangeListener);
5755
}
5856

5957
private void onPsiTreeChanged(@Nullable PsiFile file) {

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class CsvTableEditorSwing extends CsvTableEditor {
3434
private JComponent panelInfo;
3535
private JScrollPane tableScrollPane;
3636
private JPanel panelTop;
37-
3837
private JTable rowHeadersTable;
3938

4039
private int baseFontHeight;
@@ -44,7 +43,6 @@ public class CsvTableEditorSwing extends CsvTableEditor {
4443
protected final CsvTableEditorMouseListener tableEditorMouseListener;
4544
protected final CsvTableEditorKeyListener tableEditorKeyListener;
4645
protected final CsvTableEditorMouseWheelListener tableEditorMouseWheelListener;
47-
4846
private boolean listenerApplied = false;
4947

5048

@@ -236,7 +234,7 @@ public void selectColumn(int currentColumn, boolean append) {
236234

237235
@NotNull
238236
@Override
239-
public CsvTableActions getActions() {
237+
public CsvTableActions<CsvTableEditorSwing> getActions() {
240238
return this.tableEditorActions;
241239
}
242240

src/main/java/net/seesharpsoft/intellij/plugins/csv/psi/CsvPsiTreeUpdater.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class CsvPsiTreeUpdater implements PsiFileHolder, Suspendable {
3030

3131
private final CsvPsiParserFileType myFileType;
3232

33-
protected final EventListenerList listenerList = new EventListenerList();
33+
protected final EventListenerList myEventListenerList = new EventListenerList();
3434

3535
private List<PsiAction> myUncommittedActions = new ArrayList<>();
3636

@@ -83,7 +83,6 @@ public PsiFile getPsiFile() {
8383
@Override
8484
public void dispose() {
8585
Suspendable.super.dispose();
86-
myUncommittedActions = null;
8786
}
8887

8988
public @Nullable PsiElement createValueSeparator() {
@@ -95,7 +94,7 @@ public void dispose() {
9594
}
9695

9796
public void doAction(PsiAction action) {
98-
myUncommittedActions.add(action);
97+
if (myUncommittedActions != null) myUncommittedActions.add(action);
9998
}
10099

101100
public void appendEmptyFields(@NotNull PsiElement anchor, int no) {
@@ -325,7 +324,6 @@ public synchronized void commit() {
325324
try {
326325
actionsToCommit.forEach(PsiAction::execute);
327326
} finally {
328-
PsiDocumentManager.getInstance(getPsiFile().getProject()).doPostponedOperationsAndUnblockDocument(getDocument());
329327
resume();
330328
fireCommitted();
331329
}
@@ -354,16 +352,16 @@ private boolean doCommit(@NotNull Runnable runnable) {
354352
}
355353

356354
public void addCommitListener(CommitListener l) {
357-
listenerList.add(CommitListener.class, l);
355+
myEventListenerList.add(CommitListener.class, l);
358356
}
359357

360358
public void removeCommitListener(CommitListener l) {
361-
listenerList.remove(CommitListener.class, l);
359+
myEventListenerList.remove(CommitListener.class, l);
362360
}
363361

364362
protected void fireCommitted() {
365363
// Guaranteed to return a non-null array
366-
Object[] listeners = listenerList.getListenerList();
364+
Object[] listeners = myEventListenerList.getListenerList();
367365
// Process the listeners last to first, notifying
368366
// those that are interested in this event
369367
for (int i = listeners.length - 2; i >= 0; i -= 2) {

src/main/java/net/seesharpsoft/intellij/util/CheckedDisposableAwareRunnable.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/main/java/net/seesharpsoft/intellij/util/Suspendable.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.HashMap;
66
import java.util.Map;
7+
import java.util.concurrent.ConcurrentHashMap;
78

89
public interface Suspendable extends Disposable {
910
SuspensionMonitor MONITOR = new SuspensionMonitor();
@@ -25,14 +26,14 @@ default void dispose() {
2526
}
2627

2728
class SuspensionMonitor {
28-
private final Map<Suspendable, Integer> suspendableCounterMap = new HashMap<>();
29+
private final Map<Suspendable, Integer> suspendableCounterMap = new ConcurrentHashMap<>();
2930

3031
private Integer getSuspendableCounter(Suspendable suspendable) {
3132
if (suspendableCounterMap.containsKey(suspendable)) return suspendableCounterMap.get(suspendable);
3233
return null;
3334
}
3435

35-
void suspend(Suspendable suspendable) {
36+
synchronized void suspend(Suspendable suspendable) {
3637
Integer suspendableCounter = getSuspendableCounter(suspendable);
3738
if (suspendableCounter == null) {
3839
suspendableCounterMap.put(suspendable, 1);
@@ -41,7 +42,7 @@ void suspend(Suspendable suspendable) {
4142
}
4243
}
4344

44-
void resume(Suspendable suspendable) {
45+
synchronized void resume(Suspendable suspendable) {
4546
Integer suspendableCounter = getSuspendableCounter(suspendable);
4647
// this usually shouldn't happen but doesn't hurt, so fail gracefully
4748
if (suspendableCounter == null) return;
@@ -55,7 +56,7 @@ boolean isSuspended(Suspendable suspendable) {
5556
return suspendableCounter != null;
5657
}
5758

58-
void unwatch(Suspendable suspendable) {
59+
synchronized void unwatch(Suspendable suspendable) {
5960
suspendableCounterMap.remove(suspendable);
6061
}
6162
}

0 commit comments

Comments
 (0)