mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
try to avoid NPE if two threads modify library list
This commit is contained in:
parent
629509f302
commit
34b0813530
@ -50,29 +50,29 @@ public class LibraryList extends LinkedList<UserLibrary> {
|
|||||||
super(ideLibs);
|
super(ideLibs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserLibrary getByName(String name) {
|
public synchronized UserLibrary getByName(String name) {
|
||||||
for (UserLibrary l : this)
|
for (UserLibrary l : this)
|
||||||
if (l.getName().equals(name))
|
if (l.getName().equals(name))
|
||||||
return l;
|
return l;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOrReplace(UserLibrary lib) {
|
public synchronized void addOrReplace(UserLibrary lib) {
|
||||||
remove(lib);
|
remove(lib);
|
||||||
add(lib);
|
add(lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(UserLibrary lib) {
|
public synchronized void remove(UserLibrary lib) {
|
||||||
UserLibrary l = getByName(lib.getName());
|
UserLibrary l = getByName(lib.getName());
|
||||||
if (l != null)
|
if (l != null)
|
||||||
super.remove(l);
|
super.remove(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sort() {
|
public synchronized void sort() {
|
||||||
Collections.sort(this, UserLibrary.CASE_INSENSITIVE_ORDER);
|
Collections.sort(this, UserLibrary.CASE_INSENSITIVE_ORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LibraryList filterLibrariesInSubfolder(File subFolder) {
|
public synchronized LibraryList filterLibrariesInSubfolder(File subFolder) {
|
||||||
LibraryList res = new LibraryList();
|
LibraryList res = new LibraryList();
|
||||||
for (UserLibrary lib : this) {
|
for (UserLibrary lib : this) {
|
||||||
if (FileUtils.isSubDirectory(subFolder, lib.getInstalledFolder())) {
|
if (FileUtils.isSubDirectory(subFolder, lib.getInstalledFolder())) {
|
||||||
@ -82,7 +82,7 @@ public class LibraryList extends LinkedList<UserLibrary> {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasLibrary(UserLibrary lib) {
|
public synchronized boolean hasLibrary(UserLibrary lib) {
|
||||||
for (UserLibrary l : this)
|
for (UserLibrary l : this)
|
||||||
if (l == lib) return true;
|
if (l == lib) return true;
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user