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

Method getName on class java.lang.reflect.Method not allowed #969

Closed
whatacold opened this issue Aug 13, 2021 · 4 comments
Closed

Method getName on class java.lang.reflect.Method not allowed #969

whatacold opened this issue Aug 13, 2021 · 4 comments

Comments

@whatacold
Copy link

version

Babashka v0.5.1, downloaded from https://github.com/babashka/babashka/releases/download/v0.5.1/babashka-0.5.1-linux-amd64.tar.gz.

platform

Linux

problem

I'm not 100% sure if this is a bug, but it works on Clojure clj with the following code snippet:

(defn class-methods [x]
 (let [c (if (class? x) x (class x))]
  (-> (map #(.getName %1)
           (.getMethods c))
      ;; seq
      sort
      distinct)))

(class-methods \a)

It will return something like ("charCount" "charValue" ... "valueOf" "wait")

repro

Here is the evaluations of the code snippet in bb:

$ bb
Babashka v0.5.1 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (defn class-methods [x]
 (let [c (if (class? x) x (class x))]
  (-> (map #(.getName %1)
           (.getMethods c))
      ;; seq
      sort
      distinct)))
#'user/class-methods

user=> (class-methods \a)
Method getName on class java.lang.reflect.Method not allowed! [at <repl>]

expected behavior

Return the Java class methods as in clj.

@borkdude
Copy link
Collaborator

borkdude commented Aug 13, 2021

@whatacold Babashka has a subset of classes from the Java ecosystem available: it hasn't got all of them as this would make the binary bigger. So if classes are useful for scripting they will get added. I will see how much this class adds to the image.

@borkdude
Copy link
Collaborator

It adds about 10mb in the macOS native image when I add this class. I could try restrict access to the .getName method. Perhaps it's better to ask: why would it be important to have this in bb?

@borkdude
Copy link
Collaborator

OK, I've added the getName method only, that doesn't really trigger a big increase in binary size, so the above example will work with bb master now.

@whatacold
Copy link
Author

Wow, thanks for the quick fix.

It adds about 10mb in the macOS native image when I add this class. I could try restrict access to the .getName method. Perhaps it's better to ask: why would it be important to have this in bb?

Sorry for the late reply.

I was not sure if this is an issue, but now I understand that bb has a consideration to limit its size. I found this error when I played around with Clojure and bb, so I can't say I must have getName, but it would be nice to explore Java methods in bb REPL if possible.

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