Skip to content

Commit

Permalink
Fix null pointers
Browse files Browse the repository at this point in the history
Signed-off-by: DevDrizzy <[email protected]>
  • Loading branch information
DevDrizzy committed Feb 18, 2023
1 parent 0a41294 commit 3c20ceb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 0 additions & 1 deletion StorageAPI.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: org.github.paperspigot:1.8.8:1.8.8" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.mongodb:mongo-java-driver:3.12.10" level="project" />
<orderEntry type="library" name="Maven: me.carleslc.Simple-YAML:Simple-Yaml:1.8.3" level="project" />
<orderEntry type="library" name="Maven: me.carleslc.Simple-YAML:Simple-Configuration:1.8.3" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.33" level="project" />
</component>
</module>
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<groupId>xyz.refinedev.api</groupId>
<artifactId>StorageAPI</artifactId>
<version>1.5</version>
<version>1.6</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -122,6 +122,13 @@
<groupId>me.carleslc.Simple-YAML</groupId>
<artifactId>Simple-Yaml</artifactId>
<version>1.8.3</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>me.carleslc.Simple-YAML</groupId>
<artifactId>Simple-Configuration</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package xyz.refinedev.api.storage.impl;

import com.google.common.base.Preconditions;

import org.bukkit.plugin.java.JavaPlugin;

import xyz.refinedev.api.storage.YamlStorage;
import xyz.refinedev.api.storage.annotations.ConfigValue;

Expand All @@ -13,7 +16,7 @@ public abstract class ParentYamlStorage extends YamlStorage {
* Set based cache for child storages of this Parent Storage
* We keep it concurrent to allow asynchronous file I/O
*/
private final Set<ChildYamlStorage> childStorages = Collections.synchronizedSet(new HashSet<>());
private Set<ChildYamlStorage> childStorages;

/**
* Initiation method for a config file
Expand All @@ -31,6 +34,13 @@ public ParentYamlStorage(JavaPlugin plugin, String name) {
* @param storage {@link ChildYamlStorage storage}
*/
public void addChildStorage(ChildYamlStorage storage) {
Preconditions.checkNotNull(storage, "[StorageAPI] Child Storage can not be null!");

// Bypass for constructor being called before default variable initialization
if (childStorages == null) {
this.childStorages = Collections.synchronizedSet(new HashSet<>());
}

this.childStorages.add(storage);
}

Expand All @@ -46,6 +56,9 @@ public List<Field> getConfigFields() {
// Add child fields
this.childStorages.stream().map(ChildYamlStorage::getConfigFields).forEach(annotatedFields::addAll);

Preconditions.checkArgument(annotatedFields.stream().allMatch(field -> field.isAnnotationPresent(ConfigValue.class)),
"[Storage-API] One of your field is missing annotation!");

// Sort according to priority
annotatedFields.sort(Comparator.comparingInt(field -> field.getAnnotation(ConfigValue.class).priority()));

Expand Down

0 comments on commit 3c20ceb

Please sign in to comment.