From e281388b240af1a2369e29e56e3af4331fbc4e49 Mon Sep 17 00:00:00 2001 From: Viktor Sidochenko Date: Mon, 21 Jun 2021 18:02:28 +0700 Subject: [PATCH] Fix no field exception --- .../sbtqa/tag/api/utils/PlaceholderUtils.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/plugins/rest-plugin/src/main/java/ru/sbtqa/tag/api/utils/PlaceholderUtils.java b/plugins/rest-plugin/src/main/java/ru/sbtqa/tag/api/utils/PlaceholderUtils.java index 8ca0cfd6..f884d5e7 100644 --- a/plugins/rest-plugin/src/main/java/ru/sbtqa/tag/api/utils/PlaceholderUtils.java +++ b/plugins/rest-plugin/src/main/java/ru/sbtqa/tag/api/utils/PlaceholderUtils.java @@ -33,12 +33,10 @@ public static String replaceTemplatePlaceholders(EndpointEntry entry, String str Object parameterValue = parameter.getValue(); if (isFieldExists(entry, parameterName)) { - try { - string = replacePlaceholder(string, entry.getClass() - .getDeclaredField(parameterName), parameterName, parameterValue); - } catch (NoSuchFieldException e) { - throw new AutotestError("This error should never appear", e); - } + Field declaredField = FieldUtils.getAllFieldsList(entry.getClass()) + .stream().filter(field -> field.getName().equals(parameterName)) + .findFirst().orElseThrow(() -> new AutotestError("This error should never appear")); + string = replacePlaceholder(string, declaredField, parameterName, parameterValue); } else { string = replacePlaceholder(string, null, parameterName, parameterValue); } @@ -63,12 +61,9 @@ public static String replaceJsonTemplatePlaceholders(EndpointEntry entry, String Object parameterValue = parameter.getValue(); if (isFieldExists(entry, parameterName)) { - Field declaredField; - try { - declaredField = entry.getClass().getDeclaredField(parameterName); - } catch (NoSuchFieldException e) { - throw new AutotestError("This error should never appear", e); - } + Field declaredField = FieldUtils.getAllFieldsList(entry.getClass()) + .stream().filter(field -> field.getName().equals(parameterName)) + .findFirst().orElseThrow(() -> new AutotestError("This error should never appear")); jsonString = replacePlaceholder(jsonString, declaredField, parameterName, parameterValue); } else { jsonString = replacePlaceholder(jsonString, null, parameterName, parameterValue); @@ -80,7 +75,7 @@ public static String replaceJsonTemplatePlaceholders(EndpointEntry entry, String } private static boolean isFieldExists(EndpointEntry entry, String fieldName) { - return Arrays.stream(FieldUtils.getAllFields(entry.getClass())) + return FieldUtils.getAllFieldsList(entry.getClass()).stream() .anyMatch(field -> field.getName().equals(fieldName)); }