Skip to content

Commit

Permalink
Improved arrays validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigal committed Apr 13, 2021
1 parent 7d3ff09 commit a39b07d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ maven {
url = 'https://repo.mikigal.pl/releases'
}
compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.1.3'
compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.1.4'
```

#### Maven
Expand All @@ -33,7 +33,7 @@ compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.1.3'
<dependency>
<groupId>pl.mikigal</groupId>
<artifactId>ConfigAPI</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
<scope>compile</scope>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'pl.mikigal'
version '1.1.3'
version '1.1.4'

publishing {
repositories {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/pl/mikigal/config/BukkitConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public void set(String path, Object value, Comment comment) {

@Override
public void set(String path, Object value) {
if (value != null && value.getClass().isArray()) {
throw new InvalidConfigException("Arrays are not supported, use Collection instead");
}

if (!(value instanceof Collection) && !(value instanceof Map) && (value == null || TypeUtils.isSimpleType(value))) {
super.set(path, value);

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/pl/mikigal/config/ConfigInvocationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ private void prepareMethods() {
continue;
}

if (method.getReturnType().isArray()) {
throw new InvalidConfigException("Arrays are not supported, use Collection instead");
}

if (!method.isDefault()) {
throw new InvalidConfigException("Getter method " + name + " has not default value");
}
Expand All @@ -182,6 +186,10 @@ private void prepareMethods() {
continue;
}

if (method.getReturnType().isArray()) {
throw new InvalidConfigException("Arrays are not supported, use Collection instead");
}

if (method.isDefault()) {
throw new InvalidConfigException("Setter method " + name + " has default value");
}
Expand Down

0 comments on commit a39b07d

Please sign in to comment.