4d92a4
From 2b813829d02b89206493520eb86075a43b145db9 Mon Sep 17 00:00:00 2001
4d92a4
From: Roman Vais <rvais@redhat.com>
4d92a4
Date: Tue, 13 Jun 2017 13:24:24 +0200
4d92a4
Subject: [PATCH] ParseValues-NullPointerException-patch
4d92a4
4d92a4
---
4d92a4
 .../java/com/beust/jcommander/Parameterized.java   | 27 ++++++++++++++++++++--
4d92a4
 1 file changed, 25 insertions(+), 2 deletions(-)
4d92a4
4d92a4
diff --git a/src/main/java/com/beust/jcommander/Parameterized.java b/src/main/java/com/beust/jcommander/Parameterized.java
4d92a4
index 3264008..e937a66 100644
4d92a4
--- a/src/main/java/com/beust/jcommander/Parameterized.java
4d92a4
+++ b/src/main/java/com/beust/jcommander/Parameterized.java
4d92a4
@@ -13,6 +13,8 @@ import java.lang.reflect.Type;
4d92a4
 import java.util.Collections;
4d92a4
 import java.util.List;
4d92a4
 import java.util.Set;
4d92a4
+import java.util.logging.Level;
4d92a4
+import java.util.logging.Logger;
4d92a4
 
4d92a4
 /**
4d92a4
  * Encapsulate a field or a method annotated with @Parameter or @DynamicParameter
4d92a4
@@ -180,12 +182,33 @@ public class Parameterized {
4d92a4
       String fieldName = Character.toLowerCase(name.charAt(3)) + name.substring(4);
4d92a4
       Object result = null;
4d92a4
       try {
4d92a4
-        Field field = method.getDeclaringClass().getDeclaredField(fieldName);
4d92a4
+        Field field = object.getClass().getDeclaredField(fieldName);
4d92a4
         if (field != null) {
4d92a4
           setFieldAccessible(field);
4d92a4
           result = field.get(object);
4d92a4
         }
4d92a4
-      } catch(NoSuchFieldException | IllegalAccessException ex) {
4d92a4
+      } catch(NoSuchFieldException ex) {
4d92a4
+        Class clazz = object.getClass();
4d92a4
+        Field found = null;
4d92a4
+        while (clazz != null && method.getDeclaringClass().isAssignableFrom(clazz)) {
4d92a4
+          try {
4d92a4
+            found = clazz.getDeclaredField(fieldName);
4d92a4
+          } catch (NoSuchFieldException nfex) {
4d92a4
+            // ignore
4d92a4
+          }
4d92a4
+          if (found != null) break;
4d92a4
+          clazz = clazz.getSuperclass();
4d92a4
+        }
4d92a4
+        if (found != null) {
4d92a4
+          setFieldAccessible(found);
4d92a4
+          try {
4d92a4
+            result = found.get(object);
4d92a4
+          } catch (IllegalAccessException iex) {
4d92a4
+            // ignore
4d92a4
+          }
4d92a4
+        }
4d92a4
+
4d92a4
+      } catch(IllegalAccessException ex) {
4d92a4
         // ignore
4d92a4
       }
4d92a4
       return result;
4d92a4
-- 
4d92a4
2.7.4
4d92a4