Skip to content

Commit 34b0813

Browse files
committed
try to avoid NPE if two threads modify library list
1 parent 629509f commit 34b0813

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

arduino-core/src/processing/app/packages/LibraryList.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,29 @@ public LibraryList(List<UserLibrary> ideLibs) {
5050
super(ideLibs);
5151
}
5252

53-
public UserLibrary getByName(String name) {
53+
public synchronized UserLibrary getByName(String name) {
5454
for (UserLibrary l : this)
5555
if (l.getName().equals(name))
5656
return l;
5757
return null;
5858
}
5959

60-
public void addOrReplace(UserLibrary lib) {
60+
public synchronized void addOrReplace(UserLibrary lib) {
6161
remove(lib);
6262
add(lib);
6363
}
6464

65-
public void remove(UserLibrary lib) {
65+
public synchronized void remove(UserLibrary lib) {
6666
UserLibrary l = getByName(lib.getName());
6767
if (l != null)
6868
super.remove(l);
6969
}
7070

71-
public void sort() {
71+
public synchronized void sort() {
7272
Collections.sort(this, UserLibrary.CASE_INSENSITIVE_ORDER);
7373
}
7474

75-
public LibraryList filterLibrariesInSubfolder(File subFolder) {
75+
public synchronized LibraryList filterLibrariesInSubfolder(File subFolder) {
7676
LibraryList res = new LibraryList();
7777
for (UserLibrary lib : this) {
7878
if (FileUtils.isSubDirectory(subFolder, lib.getInstalledFolder())) {
@@ -82,7 +82,7 @@ public LibraryList filterLibrariesInSubfolder(File subFolder) {
8282
return res;
8383
}
8484

85-
public boolean hasLibrary(UserLibrary lib) {
85+
public synchronized boolean hasLibrary(UserLibrary lib) {
8686
for (UserLibrary l : this)
8787
if (l == lib) return true;
8888
return false;

0 commit comments

Comments
 (0)