<< Back to previous view

[CLJ-1183] java interop - cannot call a final method on non-public superclass Created: 13/Mar/13  Updated: 17/Nov/13  Resolved: 17/Nov/13

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.4, Release 1.5
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Shlomi Assignee: Unassigned
Resolution: Duplicate Votes: 1
Labels: interop

Attachments: GZip Archive call-test.tar.gz    
Approval: Triaged


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

Comment by Shlomi [ 13/Mar/13 6:51 AM ]

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)

Comment by zoowar [ 16/May/13 12:05 PM ]

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

Comment by Matthew Phillips [ 18/May/13 3:48 AM ]

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.

Comment by Shlomi [ 18/May/13 4:31 AM ]

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

Comment by Matthew Phillips [ 18/May/13 7:22 PM ]

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


Comment by Shlomi [ 15/Nov/13 6:17 PM ]

been some time - any plans on addressing this issue?

Comment by Alex Miller [ 16/Nov/13 5:00 PM ]

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.

Comment by Shlomi [ 17/Nov/13 8:12 AM ]

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..

Comment by Stuart Sierra [ 17/Nov/13 1:01 PM ]

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

Comment by Shlomi [ 17/Nov/13 1:28 PM ]

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

Comment by Alex Miller [ 17/Nov/13 10:21 PM ]

Duplicate of CLJ-1243

Generated at Fri Jan 20 01:56:00 CST 2017 using JIRA 4.4#649-r158309.