运行测试来比较 2 个 XML 对象时出现此错误 -
org.assertj.core.util.introspection.IntrospectionError:
Can't find any field or property with name 'orig_second'.
Error when introspecting properties was :
- No getter for property 'orig_second' in com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl
Error when introspecting fields was :
- Unable to obtain the value of the field <'orig_second'> from <2023-06-06T16:58:29.053Z>
Caused by: org.assertj.core.util.introspection.IntrospectionError: Unable to obtain the value of the field <'orig_second'> from <2023-06-06T16:58:29.053Z>
at org.assertj.core.util.introspection.FieldSupport.readSimpleField(FieldSupport.java:248)
at org.assertj.core.util.introspection.FieldSupport.fieldValue(FieldSupport.java:202)
at org.assertj.core.util.introspection.PropertyOrFieldSupport.getSimpleValue(PropertyOrFieldSupport.java:75)
... 50 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private transient int com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.orig_second accessible: module java.xml does not "opens com.sun.org.apache.xerces.internal.jaxp.datatype" to unnamed module @36c88a32
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at org.assertj.core.util.introspection.FieldUtils.getField(FieldUtils.java:67)
at org.assertj.core.util.introspection.FieldUtils.readField(FieldUtils.java:143)
at org.assertj.core.util.introspection.FieldSupport.readSimpleField(FieldSupport.java:208)
... 52 more
使用Java 17
几天前正在工作,但突然收到此错误,尚未更改任何库版本或代码。
尝试使用
withEqualsForType(Objects::equals,XMLGregorianCalendar.class)
例如:
assertThat(actual).usingRecursiveComparison()
.withEqualsForType(Objects::equals,XMLGregorianCalendar.class)
.isEqualTo(expected);