Skip to content

Commit

Permalink
#550 Do not rely on exceptions for flow control in HISinOneResolver#g…
Browse files Browse the repository at this point in the history
…etFieldValue
  • Loading branch information
Possommi committed Dec 13, 2024
1 parent 5e33401 commit 9e5de0b
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.lang.reflect.Field;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -841,14 +842,15 @@ protected Object getFieldValue(SysValue sysValue, String fieldName) {
Field field = null;

/* lookup field in class hierarchy */
while (clazz != null && field == null) {
try {
LOGGER.debug("Checking for field {} in {}", fieldName, clazz.getSimpleName());
field = clazz.getDeclaredField(fieldName);
} catch (Exception e) {
while (field == null && clazz != null) {
LOGGER.debug("Checking for field {} in {}", fieldName, clazz.getSimpleName());
Optional<Field> f = Arrays.stream(clazz.getDeclaredFields())
.filter(df -> df.getName().equals(fieldName)).findFirst();
if (f.isPresent()) {
field = f.get();
} else {
LOGGER.debug("Field {} could not be obtained from {}. Checking superclass {}", fieldName,
clazz.getSimpleName(),
clazz.getSuperclass().getSimpleName());
clazz.getSimpleName(), clazz.getSuperclass().getSimpleName());
}
clazz = clazz.getSuperclass();
}
Expand Down

0 comments on commit 9e5de0b

Please sign in to comment.