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

InaccessibleObjectException: Unable to make field protected boolean javax.swing.AbstractAction.enabled #206

Closed
don-vip opened this issue Aug 27, 2018 · 9 comments
Labels

Comments

@don-vip
Copy link
Contributor

don-vip commented Aug 27, 2018

What steps will reproduce the problem?

Running org.openstreetmap.josm.data.osm.search.SearchCompilerTest with JDK 11 and --illegal-access=deny

What is the code that triggers this problem?

@Test
public void testEqualsContract() {
    Set<Class<? extends Match>> matchers = TestUtils.getJosmSubtypes(Match.class);
    for (Class<?> c : matchers) {
        EqualsVerifier.forClass(c).usingGetClass()
            .suppress(Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT)
            .withPrefabValues(TaggingPreset.class, newTaggingPreset("foo"), newTaggingPreset("bar"))
            .verify();
    }
}

private static TaggingPreset newTaggingPreset(String name) {
    TaggingPreset result = new TaggingPreset();
    result.name = name;
    return result;
}

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

public class TaggingPreset extends javax.swing.AbstractAction {
    ....
    // equals and hashCode are not redefined in this class
}

What error message or stack trace does EqualsVerifier give?

java.lang.reflect.InaccessibleObjectException: Unable to make field protected boolean javax.swing.AbstractAction.enabled accessible: module java.desktop does not "opens javax.swing" to unnamed module @67065cff
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280)
	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:176)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:170)
	at nl.jqno.equalsverifier.internal.reflection.FieldAccessor.modify(FieldAccessor.java:177)
	at nl.jqno.equalsverifier.internal.reflection.FieldAccessor.copyTo(FieldAccessor.java:152)
	at nl.jqno.equalsverifier.internal.reflection.ObjectAccessor.copyInto(ObjectAccessor.java:116)
	at nl.jqno.equalsverifier.internal.reflection.ObjectAccessor.copy(ObjectAccessor.java:81)
	at nl.jqno.equalsverifier.EqualsVerifier.withPrefabValues(EqualsVerifier.java:137)
	at org.openstreetmap.josm.data.osm.search.SearchCompilerTest.testEqualsContract(SearchCompilerTest.java:721)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
	at org.openstreetmap.josm.testutils.JOSMTestRules$TimeoutThread.run(JOSMTestRules.java:684)

What did you expect?

No illegal access :)

Which version of EqualsVerifier are you using?

2.5.1

Please provide any additional information below.

@jqno
Copy link
Owner

jqno commented Aug 28, 2018

Hi!

This is kind of a confusing issue, since I can't simply copy and paste the code into my IDE and run it to see what's wrong.

I see a mention of Swing in the stack trace. Where does that come from in the code?

@don-vip
Copy link
Contributor Author

don-vip commented Aug 28, 2018

The TaggingPreset class we use in prefab values extends javax.swing.AbstractAction, I have edited the description to make it clearer.

@don-vip
Copy link
Contributor Author

don-vip commented Aug 28, 2018

Standalone example:

public class A {
    private B b;

    @Override
    public int hashCode() {
        return 31 + ((b == null) ? 0 : b.hashCode());
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null || getClass() != obj.getClass())
            return false;
        return java.util.Objects.equals(b, ((A) obj).b);
    }
}

public class B extends javax.swing.AbstractAction {

    public B(String name) {
        super(name);
    }

    @Override
    public void actionPerformed(java.awt.event.ActionEvent e) {
    }
}

public class Bug206 {
    @org.junit.Test
    public void testEqualsContract() {
        nl.jqno.equalsverifier.EqualsVerifier.forClass(A.class).usingGetClass()
            .suppress(
                    nl.jqno.equalsverifier.Warning.NONFINAL_FIELDS,
                    nl.jqno.equalsverifier.Warning.INHERITED_DIRECTLY_FROM_OBJECT)
            .withPrefabValues(B.class, new B("foo"), new B("bar"))
            .verify();
    }
}

@jqno
Copy link
Owner

jqno commented Aug 29, 2018

Thanks for the update! I see the problem now, and I will look into it.

@jqno
Copy link
Owner

jqno commented Sep 13, 2018

Sorry for the radio silence. I've reproduced the issue (which was pretty easy with your update). (See also this repo.)

I've been thinking about how to deal with this, but so far I can only conclude that I'm not sure yet 😅. Is this an urgent issue for you?

@jqno jqno added the accepted label Sep 13, 2018
@don-vip
Copy link
Contributor Author

don-vip commented Sep 13, 2018

Not urgent at all. Right now it is just a warning in our CI logs. I ran the test manually with --illegal-access=deny to help us diagnose the issue. You can take your time :)
It will only become urgent if a future version of Java changes the default behaviour to --illegal-access=deny. I don't think this will happen soon.

@jqno
Copy link
Owner

jqno commented Sep 16, 2018

OK, thanks! :)
I'm currently working on a large new release, I think I'll look into this one once that release is out. I'll keep you posted.

jqno added a commit that referenced this issue Dec 24, 2018
@jqno
Copy link
Owner

jqno commented Dec 24, 2018

It's fixed in version 3.1. You'll still get the illegal reflective access warnings if you run without --illegal-access=deny, but there will be no InaccessibleObjectException when you run with it.

@jqno jqno closed this as completed Dec 24, 2018
@don-vip
Copy link
Contributor Author

don-vip commented Dec 24, 2018

Thanks Santa! 🎅 :)

akhalikov pushed a commit to akhalikov/equalsverifier that referenced this issue Nov 6, 2019
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

2 participants