62 lines
2.1 KiB
Diff
62 lines
2.1 KiB
Diff
From 4409f9ac0d8d1f64cfd00e91b91cf822d328d526 Mon Sep 17 00:00:00 2001
|
|
From: Roman Vais <rvais@redhat.com>
|
|
Date: Tue, 13 Jun 2017 13:24:24 +0200
|
|
Subject: [PATCH] ParseValues-NullPointerException-patch
|
|
|
|
---
|
|
.../com/beust/jcommander/Parameterized.java | 27 +++++++++++++++++--
|
|
1 file changed, 25 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/main/java/com/beust/jcommander/Parameterized.java b/src/main/java/com/beust/jcommander/Parameterized.java
|
|
index ba92301..eb24ce7 100644
|
|
--- a/src/main/java/com/beust/jcommander/Parameterized.java
|
|
+++ b/src/main/java/com/beust/jcommander/Parameterized.java
|
|
@@ -6,6 +6,8 @@ import com.beust.jcommander.internal.Sets;
|
|
import java.lang.annotation.Annotation;
|
|
import java.lang.reflect.*;
|
|
import java.util.*;
|
|
+import java.util.logging.Level;
|
|
+import java.util.logging.Logger;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
@@ -208,12 +210,33 @@ public class Parameterized {
|
|
String fieldName = Character.toLowerCase(name.charAt(3)) + name.substring(4);
|
|
Object result = null;
|
|
try {
|
|
- Field field = method.getDeclaringClass().getDeclaredField(fieldName);
|
|
+ Field field = object.getClass().getDeclaredField(fieldName);
|
|
if (field != null) {
|
|
setFieldAccessible(field);
|
|
result = field.get(object);
|
|
}
|
|
- } catch(NoSuchFieldException | IllegalAccessException ex) {
|
|
+ } catch(NoSuchFieldException ex) {
|
|
+ Class<?> clazz = object.getClass();
|
|
+ Field found = null;
|
|
+ while (clazz != null && method.getDeclaringClass().isAssignableFrom(clazz)) {
|
|
+ try {
|
|
+ found = clazz.getDeclaredField(fieldName);
|
|
+ } catch (NoSuchFieldException nfex) {
|
|
+ // ignore
|
|
+ }
|
|
+ if (found != null) break;
|
|
+ clazz = clazz.getSuperclass();
|
|
+ }
|
|
+ if (found != null) {
|
|
+ setFieldAccessible(found);
|
|
+ try {
|
|
+ result = found.get(object);
|
|
+ } catch (IllegalAccessException iex) {
|
|
+ // ignore
|
|
+ }
|
|
+ }
|
|
+
|
|
+ } catch(IllegalAccessException ex) {
|
|
// ignore
|
|
}
|
|
return result;
|
|
--
|
|
2.46.0
|
|
|