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