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

The cache initialized can perform side-effectful Class/forNames #842

Closed
vemv opened this issue Jan 13, 2024 · 5 comments
Closed

The cache initialized can perform side-effectful Class/forNames #842

vemv opened this issue Jan 13, 2024 · 5 comments

Comments

@vemv
Copy link
Member

vemv commented Jan 13, 2024

https://clojurians.slack.com/archives/C0617A8PQ/p1705167808132879

Although

(Class/forName (str class-sym)
false ;; Don't initialize this class, avoiding side-effects
(.getContextClassLoader (Thread/currentThread)))
aims to avoid static initializers, perhaps there are similar calls nearby.

@vemv
Copy link
Member Author

vemv commented Jan 13, 2024

False alarm - the user's java code was based on final static fields, not static initializers.

We cannot work around those. It's a pretty extreme edge case and there's an easy refactoring path (static fields -> static initializers).

@vemv vemv closed this as completed Jan 13, 2024
@hugoduncan
Copy link
Member

Is there anything to be done to avoid someone in this situation going down the path of trying to debug what is going on?

@hugoduncan
Copy link
Member

hugoduncan commented Jan 14, 2024

Unfortunately the call to orchard.info/info in warmup-orchard-caches! is initialising the java class.

info calls orchard.meta/resolve-var which calls ns-resolve.

@hugoduncan hugoduncan reopened this Jan 14, 2024
@vemv
Copy link
Member Author

vemv commented Jan 14, 2024

Is there anything to be done to avoid someone in this situation going down the path of trying to debug what is going on?

Considering that as of today we offer support practically 7 days a week (my pleasure 🙂) I'm not immediately concerned by this meta-problem.

Perhaps we can add an integration test ensuring that no requires are performed, for the supported use cases:

  • Vanilla clojure code
  • Java classes with requires performed in the static class initializer

info calls orchard.meta/resolve-var which calls ns-resolve.

Good catch! I see, unfortunately the Java class/record type symbol clause is not the first one in the or: https://github.com/clojure-emacs/orchard/blob/951fdbe26cf5146ef070b905a99508e6ef9997e1/src/orchard/info.clj#L72-L81

However there's an easy fix - change info for info-java

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