-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make json model thread safe to fix ArrayIndexOutOfBoundsException #61
- Loading branch information
Showing
2 changed files
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,19 @@ | |
import java.util.HashSet; | ||
|
||
/** | ||
* Model json input | ||
* | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class JsonProvider { | ||
|
||
@Nullable | ||
private String name; | ||
|
||
@Nullable | ||
private JsonRawLookupElement defaults; | ||
|
||
@Nullable | ||
private Collection<JsonRawLookupElement> items = new ArrayList<>(); | ||
|
||
@SerializedName("lookup_strings") | ||
|
@@ -24,33 +31,37 @@ public class JsonProvider { | |
@Nullable | ||
private JsonProviderSource source; | ||
|
||
@Nullable | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Nullable | ||
public JsonRawLookupElement getDefaults() { | ||
return defaults; | ||
} | ||
|
||
public Collection<JsonRawLookupElement> getItems() { | ||
synchronized public Collection<JsonRawLookupElement> getItems() { | ||
if(this.myItems != null) { | ||
return this.myItems; | ||
} | ||
|
||
this.myItems = new ArrayList<>(items); | ||
Collection<JsonRawLookupElement> items = new ArrayList<>(); | ||
if(this.items != null && this.items.size() > 0) { | ||
items.addAll(this.items); | ||
} | ||
|
||
if(lookupStrings.size() > 0) { | ||
for (String lookupElement : lookupStrings) { | ||
this.myItems.add(JsonRawLookupElement.create(lookupElement)); | ||
items.add(JsonRawLookupElement.create(lookupElement)); | ||
} | ||
} | ||
|
||
return this.myItems; | ||
return this.myItems = items; | ||
} | ||
|
||
@Nullable | ||
public JsonProviderSource getSource() { | ||
return source; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters