Skip to content

Commit

Permalink
FieldMatcher: Fix access to private fields (fixes #1)
Browse files Browse the repository at this point in the history
Also report any field access failure instead of silently ignoring.
  • Loading branch information
xkr47 authored Nov 29, 2018
1 parent 7fccd0c commit ef6e81a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/nitorcreations/matchers/FieldMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ protected boolean matchesSafely(T item, Description mismatchDescription) {
if (valueMatcher == null)
return true;
try {
field.setAccessible(true);
return valueMatcher.matches(field.get(item));
} catch (IllegalAccessException e) {
return false;
throw new RuntimeException("Failed to access field " + fieldName + " in " + item.getClass().getName(), e);
}
}

Expand Down

0 comments on commit ef6e81a

Please sign in to comment.