From 0db6460f37ac60477fa42bf9d9f1b4ef8d7d1c7c Mon Sep 17 00:00:00 2001 From: sjoshid Date: Sun, 10 May 2020 15:57:22 -0400 Subject: [PATCH] PR for https://github.com/influxdata/influxdb-java/issues/670 1) Handling NPE --- .../org/influxdb/impl/InfluxDBResultMapper.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/influxdb/impl/InfluxDBResultMapper.java b/src/main/java/org/influxdb/impl/InfluxDBResultMapper.java index 3bb829bd0..48e618d7b 100644 --- a/src/main/java/org/influxdb/impl/InfluxDBResultMapper.java +++ b/src/main/java/org/influxdb/impl/InfluxDBResultMapper.java @@ -333,9 +333,6 @@ void setFieldValue(final T object, final Field field, final Method fieldSett if (!field.isAccessible()) { field.setAccessible(true); } - if (!fieldSetter.isAccessible()) { - fieldSetter.setAccessible(true); - } if (assignInstant(fieldType, field, fieldSetter, object, value, precision) || assignString(fieldType, field, fieldSetter, object, value) || assignDouble(fieldType, field, fieldSetter, object, value) @@ -370,7 +367,7 @@ boolean assignInstant(final Class fieldType, final Field field, final Met } else { throw new InfluxDBMapperException("Unsupported type " + field.getClass() + " for field " + field.getName()); } - if(fieldSetter != null && fieldSetter.isAccessible()) { + if(fieldSetter != null) { fieldSetter.invoke(object, instant); isInstantAssigned = true; } else { @@ -385,7 +382,7 @@ boolean assignString(final Class fieldType, final Field field, final Meth boolean isStringAssigned = false; if(String.class.isAssignableFrom(fieldType)) { final String stringValue = String.valueOf(value); - if(fieldSetter != null && fieldSetter.isAccessible()) { + if(fieldSetter != null) { fieldSetter.invoke(object, stringValue); isStringAssigned = true; } else { @@ -399,7 +396,7 @@ boolean assignString(final Class fieldType, final Field field, final Meth boolean assignDouble(final Class fieldType, final Field field, final Method fieldSetter, final T object, final Object value) throws InvocationTargetException, IllegalAccessException { boolean isDoubleAssigned = false; if(double.class.isAssignableFrom(fieldType) || Double.class.isAssignableFrom(fieldType)) { - if(fieldSetter != null && fieldSetter.isAccessible()) { + if(fieldSetter != null) { fieldSetter.invoke(object, value); isDoubleAssigned = true; } else if(double.class.isAssignableFrom(fieldType)) { @@ -418,7 +415,7 @@ boolean assignLong(final Class fieldType, final Field field, final Method boolean isLongAssigned = false; if(long.class.isAssignableFrom(fieldType) || Long.class.isAssignableFrom(fieldType)) { final long longValue = ((Double) value).longValue(); - if(fieldSetter != null && fieldSetter.isAccessible()) { + if(fieldSetter != null) { fieldSetter.invoke(object, longValue); isLongAssigned = true; } else if(long.class.isAssignableFrom(fieldType)) { @@ -436,7 +433,7 @@ boolean assignInteger(final Class fieldType, final Field field, final Met boolean isIntegerAssigned = false; if(int.class.isAssignableFrom(fieldType) || Integer.class.isAssignableFrom(fieldType)) { final int intValue = ((Double) value).intValue(); - if(fieldSetter != null && fieldSetter.isAccessible()) { + if(fieldSetter != null) { fieldSetter.invoke(object, intValue); isIntegerAssigned = true; } else if(int.class.isAssignableFrom(fieldType)) { @@ -454,7 +451,7 @@ boolean assignBoolean(final Class fieldType, final Field field, final Met boolean isBooleanAssigned = false; if(boolean.class.isAssignableFrom(fieldType) || Boolean.class.isAssignableFrom(fieldType)) { final boolean boolValue = Boolean.parseBoolean(String.valueOf(value)); - if(fieldSetter != null && fieldSetter.isAccessible()) { + if(fieldSetter != null) { fieldSetter.invoke(object, boolValue); isBooleanAssigned = true; } else if(boolean.class.isAssignableFrom(fieldType)) {