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

Can't access lower-case static fields shadowed by static methods #8188

Open
headius opened this issue Apr 3, 2024 Discussed in #8187 · 1 comment
Open

Can't access lower-case static fields shadowed by static methods #8188

headius opened this issue Apr 3, 2024 Discussed in #8187 · 1 comment

Comments

@headius
Copy link
Member

headius commented Apr 3, 2024

Discussed in #8187

Originally posted by mrckzgl April 3, 2024
Hey, we want to access the enums in this class: https://tinkerpop.apache.org/javadocs/current/core/org/apache/tinkerpop/gremlin/structure/VertexProperty.Cardinality.html from within JRuby.
Before an upgrade of the gremlin jar this worked with: org.apache.tinkerpop.gremlin.structure.VertexProperty::Cardinality::single, but after the upgrade, static methods with the same name as the enums were added to the class (e.g. https://tinkerpop.apache.org/javadocs/current/core/org/apache/tinkerpop/gremlin/structure/VertexProperty.Cardinality.html#single(java.lang.Object). Now if we try to access the enums, JRuby complains about a missing parameter, which indicates that it instead accesses the static method.

How to distinguish between static enum and static method?

The problem is that the library defines lower-case enum. These were accessible via MyEnum::lowername before, but then the library added in static methods with the same names. Now the methods win in JRuby's proxy class, so there's no way to access the enum values anymore.

@headius
Copy link
Member Author

headius commented Apr 3, 2024

A workaround for now is to just use reflection directly to access the enum values (which are normal static fields):

[] jruby $ cat Blah.java
public enum Blah {
    blah1, blah2;

    public static void blah1() {}
}
[] jruby $ jruby -e 'p Java::Blah.blah1, Java::Blah.blah2'
nil
blah2
[] jruby $ jruby -e 'p Java::Blah.java_class.get_field("blah1").get(nil), Java::Blah.blah2'
blah1
blah2

I believe we should have java_field that can support static fields, but I could not get it to work with the current implementation.

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

1 participant