Skip to content

URLClassLoader.findClass with different behavior when called within jjs Nashorn #2823

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

Closed
brunoborges opened this issue Apr 14, 2015 · 3 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@brunoborges
Copy link

When running a script with jjs that invokes a class from a classpath configured with 'jjs -cp', that will make use of URLClassLoader.findClass, the behavior is different from when the Java library is invoked the usual way.

See log trace: https://gist.github.com/brunoborges/110af2969f2c2be7e288

To invoke code, see: https://github.com/brunoborges/nashorn/tree/master/maven/samples/springboot

@philwebb
Copy link
Member

That's weird, I wonder why URLClassLoader.findClass wouldn't find that class.

@brunoborges
Copy link
Author

That can be a bug in:

  1. URLClassLoader.findClass weird behavior when called from within Nashorn script executed with *jjs
  2. Nashorn's way to build a ClassLoader for the -cp classpath passed by with jjs
  3. Spring Boot usage of findClass, plus some weird bug inside findClass

Of course 3 is likely not true :-) #ButWhoKnows

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 17, 2016
@wilkinsona
Copy link
Member

When launched with jjs -cp, Nashorn creates a ClassLoader using the specified class path but, unlike java -cp, it does not make that ClassLoader the thread context class loader. This means we end up trying to load classes using the app class loader which can't see any of the classes that are on the class path.

Setting the thread context class loader before calling run() fixes the problem:

var SpringApplication = Packages.org.springframework.boot.SpringApplication;
java.lang.Thread.currentThread().contextClassLoader = SpringApplication.class.classLoader;

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants