Skip to content

Commit

Permalink
add ignoring NullPointerException
Browse files Browse the repository at this point in the history
  • Loading branch information
Maru32768 committed Jan 13, 2022
1 parent c8564a6 commit 9c24dbb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id "com.github.johnrengelman.shadow" version "6.1.0"
id "maven-publish"
id "idea"
}

group 'net.kunmc.lab'
Expand Down Expand Up @@ -40,13 +41,21 @@ java {
}
}

idea {
module {
downloadJavadoc = true
downloadSources = true
}
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

shadowJar {
archiveFileName = "${rootProject.name}-${version}.jar"
exclude "net/minecraft"
exclude "org/bukkit"
}
tasks.build.dependsOn tasks.shadowJar

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/net/kunmc/lab/configlib/config/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,18 @@ void replaceFields(Class<?> clazz, Object src, Object dst) {
}

private void replaceField(Field field, Object src, Object dst) throws IllegalAccessException {
List<Field> fieldList = ReflectionUtils.getFieldsIncludingSuperclasses(field.getType());
Object srcObj = field.get(src);
Object dstObj = field.get(dst);

if (fieldList.isEmpty()) {
field.set(dst, srcObj);
} else {
replaceFields(field.getType(), srcObj, dstObj);
try {
List<Field> fieldList = ReflectionUtils.getFieldsIncludingSuperclasses(field.getType());
Object srcObj = field.get(src);
Object dstObj = field.get(dst);

if (fieldList.isEmpty()) {
field.set(dst, srcObj);
} else {
replaceFields(field.getType(), srcObj, dstObj);
}
} catch (NullPointerException ignored) {
// 新しいValueが追加された時のためにNullPointerExceptionを回避する
}
}
}

0 comments on commit 9c24dbb

Please sign in to comment.