Clojure

java interop - cannot call a final method on non-public superclass

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: Release 1.4, Release 1.5
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Approval:
    Triaged

Description

when trying to call a method on a concrete class that is defined as final on its super class that is not public, the runtime throws:

"java.lang.IllegalArgumentException: Can't call public method of non-public class"

even when fully annotated, Reflection is still used and the call fails.

you can read the full description here https://groups.google.com/d/msg/clojure/p2tBMT-BIYc/mDQB8cSponMJ

I included a sample project that demonstrate the problem

Activity

Hide
Shlomi added a comment - - edited

in my sample project, i used a nested class, but i didnt have to (as pointed by Marko Topolnik). changing the java code to:

abstract class AbstractParent{
final public int x() {return 6;}
}

public class test extends AbstractParent {}

and the clojure to:

(ns call-test.core (:gen-class))
(defn -main [& args](.x ^AbstractParent (test.)))

would produce the same error,

java.lang.IllegalArgumentException: Can't call public method of non-public class: public final int AbstractParent.x()
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:88)

Show
Shlomi added a comment - - edited in my sample project, i used a nested class, but i didnt have to (as pointed by Marko Topolnik). changing the java code to: abstract class AbstractParent{ final public int x() {return 6;} } public class test extends AbstractParent {} and the clojure to: (ns call-test.core (:gen-class)) (defn -main [& args](.x ^AbstractParent (test.))) would produce the same error, java.lang.IllegalArgumentException: Can't call public method of non-public class: public final int AbstractParent.x() at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:88)
Hide
zoowar added a comment -

This issue affects the upcoming netty-4.0 release in which the public modifier of AbstractBootstrap was removed.

Show
zoowar added a comment - This issue affects the upcoming netty-4.0 release in which the public modifier of AbstractBootstrap was removed.
Hide
Matthew Phillips added a comment -

To get Netty 4 working with Clojure I had to create a set of public static Java methods for the various inaccessible Netty calls, which I then call from Clojure. A PITA, but works fine. Happy to post code if anyone would find it useful.

Show
Matthew Phillips added a comment - To get Netty 4 working with Clojure I had to create a set of public static Java methods for the various inaccessible Netty calls, which I then call from Clojure. A PITA, but works fine. Happy to post code if anyone would find it useful.
Hide
Shlomi added a comment -

Matthew, i kinda left that project after running to these and other troubles (focused on previous Netty until version 4 will become ready and be properly documented), but i'd still like to see your code. you have a github account or a gist with it?

Clojure devs - are there any plans of checking this problem out? it came up from Netty, but the problem is pretty generic

Show
Shlomi added a comment - Matthew, i kinda left that project after running to these and other troubles (focused on previous Netty until version 4 will become ready and be properly documented), but i'd still like to see your code. you have a github account or a gist with it? Clojure devs - are there any plans of checking this problem out? it came up from Netty, but the problem is pretty generic
Hide
Matthew Phillips added a comment -

Shlomi: here's a gist with the code I'm using in it. It's not comprehensive, just the bits I needed.

https://gist.github.com/scramjet/5606195

Show
Matthew Phillips added a comment - Shlomi: here's a gist with the code I'm using in it. It's not comprehensive, just the bits I needed. https://gist.github.com/scramjet/5606195
Hide
Shlomi added a comment -

been some time - any plans on addressing this issue?

Show
Shlomi added a comment - been some time - any plans on addressing this issue?
Hide
Alex Miller added a comment -

Someone (I think Stuart Sierra?) did look into this but it was not obvious what the solution could be. It is not currently being considered for Clojure 1.6 but I will bump it into Triaged for post-1.6 consideration.

Show
Alex Miller added a comment - Someone (I think Stuart Sierra?) did look into this but it was not obvious what the solution could be. It is not currently being considered for Clojure 1.6 but I will bump it into Triaged for post-1.6 consideration.
Hide
Shlomi added a comment -

Thanks Alex, I tried looking at it myself, but i couldnt find where in the code clojure chooses between emitting the correct code and going to reflective way. If Stuart or anyone could help me out, i'd be glad to continue looking into it..

Show
Shlomi added a comment - Thanks Alex, I tried looking at it myself, but i couldnt find where in the code clojure chooses between emitting the correct code and going to reflective way. If Stuart or anyone could help me out, i'd be glad to continue looking into it..
Hide
Stuart Sierra added a comment - - edited

This looks like the same problem as CLJ-1243. See there for diagnosis.

Show
Stuart Sierra added a comment - - edited This looks like the same problem as CLJ-1243. See there for diagnosis.
Hide
Shlomi added a comment -

Thanks! I wished this was posted here earlier, would have saved me some time in the past two days

Show
Shlomi added a comment - Thanks! I wished this was posted here earlier, would have saved me some time in the past two days
Hide
Alex Miller added a comment -

Duplicate of CLJ-1243

Show
Alex Miller added a comment - Duplicate of CLJ-1243

People

  • Assignee:
    Unassigned
    Reporter:
    Shlomi
Vote (1)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: