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

(maint) Fix classpath stuff for Java 9 #99

Merged
merged 3 commits into from
Jan 18, 2018

Conversation

pcarlisle
Copy link
Contributor

@pcarlisle pcarlisle commented Jan 18, 2018

We can't rely on having a modifiable classloader at all times, so make
sure one is put in place if needed.

Fixes #79

[]
(let [classloader (.. Thread currentThread getContextClassLoader)]
(when-not (last (filter modifiable-classloader? (classloader-hierarchy classloader)))
(let [new-cl (clojure.lang.DynamicClassLoader. classloader)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to just use the clojure one for this? We could implement our own pretty easily but it seemed to have what was needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems fine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/DynamicClassLoader.java#L33-L38 isn't super readable, but it seems fine and hasn't been touched in years.

@lindboe
Copy link

lindboe commented Jan 18, 2018

Commit description might be more useful if it said why we can't rely on having a modifiable classloader (even if it just says "because Java 9 no longer guarantees that" or something)

(classpath-urls (.getContextClassLoader (Thread/currentThread))))]
;; Called for side effect of ensuring there's a modifiable classloader
;; without needing to make that function public
(add-classpath "file:/nil")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part seems weird. How does add-classpath get called otherwise in real use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets called on its own in trapperkeeper. It does not normally need to be called before calling the next line, but this test wants to use some url methods after with-additional-classpath-entries removes the temporary classloader it puts there, so this makes that possible. It's not entirely clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way this test works doesn't make that much sense to begin with

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaned this up so it's not confusing anymore

AppClassLoader is no longer a URLClassLoader in Java 9 so you can't tell
it to add URLs anymore. Instead we can just add a classloader that we
can modify when we need it.
The implementation of this test was not ideal, and made worse by Java 9 changes
to classloaders. Instead of querying URLs, just add a resource to a directory
that's not normally in the class path and test that we can resolve it when it's
added and that we can't after it gets cleaned up.
Copy link
Contributor

@haus haus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ron-swanson-is-proud-of-you

@puppetcla
Copy link

CLA signed by all contributors.

@MikaelSmith
Copy link
Contributor

MikaelSmith commented Jan 18, 2018

Can we add Java 9 to the test matrix? travis-ci/travis-ci#5520 (comment) seems to have something that works.

Add java 9 and drop java 6.
@MikaelSmith MikaelSmith merged commit f126acb into puppetlabs:master Jan 18, 2018
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

Successfully merging this pull request may close these issues.

5 participants