Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal reflective access when recursively comparing XMLGregorianCalendar #2928

Closed
lcharrie opened this issue Jan 26, 2023 · 3 comments
Closed
Assignees
Labels
theme: recursive comparison An issue related to the recursive comparison type: bug A general bug

Comments

@lcharrie
Copy link

lcharrie commented Jan 26, 2023

assertThat().usingRecursiveComparison() on XMLGregorianCalendar objects triggers an illegal reflective access operation

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.assertj.core.util.introspection.FieldUtils (file:/home/lc22j176/.m2/repository/org/assertj/assertj-core/3.24.2/assertj-core-3.24.2.jar) to field com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.orig_second
WARNING: Please consider reporting this to the maintainers of org.assertj.core.util.introspection.FieldUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
  • assertj core version 3.24.2
  • java 14
  • junit-jupiter-api version 5.8.2

Test case reproducing the bug

  void AssertjXMLGregorianCalendarTest() throws Exception {

    XMLGregorianCalendar in = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    XMLGregorianCalendar out = DatatypeFactory.newInstance().newXMLGregorianCalendar();

    assertThat(out).usingRecursiveComparison().isEqualTo(in);
  }
@scordio scordio added the theme: recursive comparison An issue related to the recursive comparison label Jan 28, 2023
@scordio
Copy link
Member

scordio commented Jan 28, 2023

I'd say we also consider javax for Java types detection in DualValue.

@assertj/core do you agree?

@scordio scordio added the type: bug A general bug label Jan 28, 2023
@joel-costigliola
Copy link
Member

Yes, I think anything that AssertJ won't be able to introspect because of java policy to restrict reflective access should be compared by their equals method since there is not much else we can do.

In this case, I could fix the issue by adding com.sun.* to java types detection (javax did not solve the issue but should be added too).

@joel-costigliola joel-costigliola self-assigned this Jan 29, 2023
@joel-costigliola
Copy link
Member

@lcharrie in the meantime, you can get rid of the warning by telling the recursive comparison to compare XMLGregorianCalendar with their equals method:

  void AssertjXMLGregorianCalendarTest() throws Exception {

    XMLGregorianCalendar in = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    XMLGregorianCalendar out = DatatypeFactory.newInstance().newXMLGregorianCalendar();

    assertThat(out).usingRecursiveComparison()
                   .withEqualsForType(Objects::equals, XMLGregorianCalendar.class)
                   .isEqualTo(in);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: recursive comparison An issue related to the recursive comparison type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants