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

Java 9/10 illegal reflective access to field java.lang.Thread.name #193

Closed
ekoutanov opened this issue Apr 28, 2018 · 7 comments
Closed
Labels

Comments

@ekoutanov
Copy link

Another one for the reflective access gods...

What steps will reproduce the problem?

Run EV on a class that encapsulates java.lang.Thread on JDK 10.

What is the code that triggers this problem?

public final class EqualsVerifierThreadTest {
  private static final class ThreadHolder {
    private final Thread thread;

    @SuppressWarnings("unused")
    ThreadHolder(Thread thread) {
      this.thread = thread;
    }
    
    @Override public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      } else if (obj instanceof ThreadHolder) {
        final ThreadHolder that = (ThreadHolder) obj;
        return Objects.equals(thread, that.thread);
      } else {
        return false;
      }
    }
    
    @Override public int hashCode() {
      return Objects.hashCode(thread);
    }
  }
  
  @Test
  public void test() {
    EqualsVerifier.forClass(ThreadHolder.class)
    .withPrefabValues(Thread.class, new Thread("red"), new Thread("black")).verify();
  }
}

What error message or stack trace does EqualsVerifier give?

Test passes. Javac (run from Gradle 4.6) prints following warning:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by nl.jqno.equalsverifier.internal.reflection.FieldAccessor (file:/Users/emil/.gradle/caches/modules-2/files-2.1/nl.jqno.equalsverifier/equalsverifier/2.4.6/e4a370639189cb7d6eb80d0763bac1b15ed227b/equalsverifier-2.4.6.jar) to field java.lang.Thread.name
WARNING: Please consider reporting this to the maintainers of nl.jqno.equalsverifier.internal.reflection.FieldAccessor
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

What did you expect?

No warning.

Which version of EqualsVerifier are you using?

2.4.6

@ekoutanov ekoutanov changed the title Java 9/10 illegal reflective access Java 9/10 illegal reflective access to field java.lang.Thread.name Apr 28, 2018
@jqno
Copy link
Owner

jqno commented Apr 29, 2018

Thanks, nice catch!
I'll release the fix for this in the next version. I'll let you know when that happens.

@jqno jqno added the accepted label Apr 29, 2018
@ekoutanov
Copy link
Author

Thanks, and no rush.

@jqno
Copy link
Owner

jqno commented Jun 20, 2018

I (finally 😉) released version 2.4.7, which fixes this.

@jqno jqno closed this as completed Jun 20, 2018
@ekoutanov
Copy link
Author

Thanks for the heads up @jqno . I ran it on a couple of projects just then and no problems spotted.

@jqno
Copy link
Owner

jqno commented Jun 21, 2018 via email

@bartosz-bilicki
Copy link

bartosz-bilicki commented Sep 10, 2019

there is still warning when using version 3.19 with java 11 (test is passing)

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by nl.jqno.equalsverifier.internal.reflection.FieldAccessor (file:/../.gradle/caches/modules-2/files-2.1/nl.jqno.equalsverifier/equalsverifier/3.1.9/2f8586638e8c169da544466ad89d6eea8ea379b4/equalsverifier-3.1.9.jar) to field java.util.concurrent.atomic.AtomicReference.value
WARNING: Please consider reporting this to the maintainers of nl.jqno.equalsverifier.internal.reflection.FieldAccessor
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

My code

@Test
    void equalsContract() {
        EqualsVerifier.forClass(MySlass.class)
                .withPrefabValues(AtomicReference.class,
                        new AtomicReference<>(...),
                        new AtomicReference<>(..)
                .verify();
    }

@jqno
Copy link
Owner

jqno commented Sep 12, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants