Browse Source

little bug getting the default value

Klaas, Wilfried 6 years ago
parent
commit
7e5047994b
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/main/java/de/mcs/utils/jsap/CommandlineProcessor.java

+ 3 - 3
src/main/java/de/mcs/utils/jsap/CommandlineProcessor.java

@@ -74,7 +74,7 @@ public class CommandlineProcessor {
       try {
         if (commandLineArgs.contains(annotation.name())) {
           File file = commandLineArgs.getFile(annotation.name());
-          if ((file.getName() != null) && !"".equals(file.getName())) {
+          if ((file != null) && (file.getName() != null) && !"".equals(file.getName())) {
             method.invoke(null, file);
           } else {
             if (annotation.defaultValue() != null) {
@@ -95,11 +95,11 @@ public class CommandlineProcessor {
       try {
         String value = commandLineArgs.getString(annotation.name());
         if ((value == null) || value.isEmpty()) {
-          method.invoke(null, commandLineArgs.getString(annotation.name()));
-        } else {
           if (annotation.defaultValue() != null) {
             method.invoke(null, annotation.defaultValue());
           }
+        } else {
+          method.invoke(null, commandLineArgs.getString(annotation.name()));
         }
       } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) {
         e1.printStackTrace();