diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 926ae7a..5b468fc 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ '8', '17', '20' ] + java: [ '11', '17', '20' ] steps: - uses: actions/checkout@v3 diff --git a/src/main/java/dev/denux/dtp/internal/writer/TomlWriter.java b/src/main/java/dev/denux/dtp/internal/writer/TomlWriter.java index f04ff15..510ec28 100644 --- a/src/main/java/dev/denux/dtp/internal/writer/TomlWriter.java +++ b/src/main/java/dev/denux/dtp/internal/writer/TomlWriter.java @@ -5,6 +5,8 @@ import dev.denux.dtp.util.PrimitiveUtil; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; import java.time.temporal.TemporalAccessor; import java.util.ArrayList; import java.util.Arrays; @@ -36,19 +38,23 @@ public String writeToString() { Map, Field> subClasses = new HashMap<>(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; + if (Modifier.isStatic(field.getModifiers())) + continue; try { field.setAccessible(true); Class clazz = PrimitiveUtil.wrap(field.getType()); Object fieldObj = field.get(object); if (fieldObj == null) { try { - fieldObj = clazz.newInstance(); + clazz.getConstructor().newInstance(); } catch (InstantiationException exception) { throw new TomlWriteException(String.format("Due to the value of %s " + "being null we tried to create a new instance of %s but this also" + "failed. Skipping field.", field.getName(), clazz.getSimpleName())); - } - } + } catch (InvocationTargetException | NoSuchMethodException e) { + throw new RuntimeException(e); + } + } if (String.class.equals(clazz)) { handleString(field, fieldObj, builder); } else if (Number.class.isAssignableFrom(clazz)) {