Skip to content

Commit

Permalink
make json model thread safe to fix ArrayIndexOutOfBoundsException #61
Browse files Browse the repository at this point in the history
  • Loading branch information
Haehnchen committed Jun 15, 2017
1 parent 5f0500a commit 2564e37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/de/espend/idea/php/toolbox/dict/json/JsonProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ public static Collection<PhpToolboxProviderInterface> getProvidersInner(@NotNull
for (JsonProvider provider : fileProviders) {
JsonProviderSource source = provider.getSource();
if(source != null) {

if(sourceProviders == null) {
sourceProviders = new HashMap<>();
}

String name = provider.getName();
if(name == null) {
continue;
}

if(!sourceProviders.containsKey(name)) {
sourceProviders.put(name, new ArrayList<>(Collections.singletonList(provider)));
} else {
Expand Down

0 comments on commit 2564e37

Please sign in to comment.