Projects
Mega:23.09
beust-jcommander
_service:tar_scm:0001-ParseValues-NullPointerEx...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:tar_scm:0001-ParseValues-NullPointerException-patch.patch of Package beust-jcommander
From 2b813829d02b89206493520eb86075a43b145db9 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 --- .../java/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 3264008..e937a66 100644 --- a/src/main/java/com/beust/jcommander/Parameterized.java +++ b/src/main/java/com/beust/jcommander/Parameterized.java @@ -13,6 +13,8 @@ import java.lang.reflect.Type; import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Encapsulate a field or a method annotated with @Parameter or @DynamicParameter @@ -180,12 +182,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.7.4
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2