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

Classes with URL in them will give warning illegal reflective #340

Closed
Arbenit opened this issue Aug 27, 2020 · 7 comments
Closed

Classes with URL in them will give warning illegal reflective #340

Arbenit opened this issue Aug 27, 2020 · 7 comments

Comments

@Arbenit
Copy link

Arbenit commented Aug 27, 2020

What steps will reproduce the problem?

Create class with URL

What is the code that triggers this problem?

    @Test
    public void testEqualsAndHashCode(){
        EqualsVerifier.forClass(Pojo.class).usingGetClass().verify();
    }

Provide an example of a complete class (equals method, hashCode method, relevant fields) and a call to EqualsVerifier.

import javax.validation.constraints.NotNull;
import java.net.URL;
import java.util.Objects;

public class Pojo {

    private final URL url;

    public Pojo(@NotNull final URL url) {
        this.url = url;
    }

    @NotNull
    public URL getUrl() {
        return url;
    }


    @Override
    public boolean equals(final Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pojo pojo = (Pojo) o;
        return Objects.equals(url, pojo.url);
    }

    @Override
    public int hashCode() {
        return Objects.hash(url);
    }


}
public class PojoTest {

    static {
        try {
            URL = new URL("https://example.com/");
        } catch (MalformedURLException e) {
            throw new IllegalStateException(e);
        }
    }

    private final static URL URL;

    Pojo pojo;

    @BeforeEach
    void setUp() throws MalformedURLException {
        pojo = new Pojo(URL);
    }

    @Test
    public void testEqualsAndHashCode(){
        EqualsVerifier.forClass(Pojo.class).usingGetClass().verify();
    }
}

Remember, you have the problem right in front of you. I have to try and reproduce it in my spare time. Please help me, so that I can help you!

What error message or stack trace does EqualsVerifier give?

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by nl.jqno.equalsverifier.internal.reflection.FieldAccessor (file:/userspace/nl/jqno/equalsverifier/equalsverifier/3.4.2/equalsverifier-3.4.2.jar) to field java.net.UrlDeserializedState.protocol
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?

3.4.2

Please provide any additional information below.

@Test
    public void testEqualsAndHashCode() throws MalformedURLException {
        EqualsVerifier.forClass(Pojo.class).usingGetClass()
                      .withPrefabValues(URL.class,new URL("http://www.example.com/"), new URL("http://www.google.ca/")).verify();
    }

This will change the warning to

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by nl.jqno.equalsverifier.internal.reflection.FieldAccessor (file:/userspace/nl/jqno/equalsverifier/equalsverifier/3.4.2/equalsverifier-3.4.2.jar) to field java.net.URL.protocol 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

jqno added a commit that referenced this issue Aug 29, 2020
@jqno
Copy link
Owner

jqno commented Aug 29, 2020

I've added prefab values for java.net.URL. I have some other things I want to address, I'll let you know when I make a release.

@Arbenit
Copy link
Author

Arbenit commented Aug 31, 2020

Sorry for the late response but I think you might have to do more then just add a prefab value for java.net.url if you look at the additional information part when I added the withPrefabValues for the url the warning changed.

@jqno
Copy link
Owner

jqno commented Aug 31, 2020

Can you confirm that please? I've got the EqualsVerifier build running with --illegal-access=deny on a bunch of different JVMs, and it has not complained.

@Arbenit
Copy link
Author

Arbenit commented Aug 31, 2020

warning
THe warning only happens when I manually run the test ie click the run test button on either that test or the whole class. If I run it with maven verify instead it doesnt generate any warnings.

@jqno
Copy link
Owner

jqno commented Aug 31, 2020

Ah, that at the same time explains and doesn't explain things...
It explains why I didn't see the second warning. But why would running the test from IntelliJ give such different behaviour? That said, I need to be able to reproduce this from Maven as well if I'm going to write a test and a fix for it...

@Arbenit
Copy link
Author

Arbenit commented Aug 31, 2020

I dont really know how to get the warning to show up for the maven verify so Ill close the ticket and if in the future I run into the issue again but it also shows up on maven then Ill reopen the issue with the steps required.

@Arbenit Arbenit closed this as completed Aug 31, 2020
@jqno
Copy link
Owner

jqno commented Sep 8, 2020

I've just released version 3.4.3, which contains the prefab value.

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

No branches or pull requests

2 participants