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