Code Monkey home page Code Monkey logo

Comments (6)

ekuefler avatar ekuefler commented on May 9, 2024

So to be clear, your proposed resolution is to replace getParentClassloader in GwtMockitoTestRunner so that it returns Thread.currentThread().getContextClassLoader() instead of ClassLoader.getSystemClassLoader()?

This seems to me like it's probably the right thing to do; I'm trying to think if it might have any negative side effects. If I understand correctly, IDEA's test runner presumably works by starting a thread, setting that thread's context classloader to something magical, then executing the test on that thread. By having the parent classloader be the system classloader, we're basically bypassing whatever IDEA had set.

In most cases the context classloader will be the same as the system classloader, but in the cases where it's not it's because some tool quite explicitly wanted to use a different classloader for that thread. So it's always going to be better to respect that preference than to force the system classloader.

Does that reasoning sound correct? If so and no one objects I'll make the change. If this is blocking you, you can create your own subclass of GwtMockitoTestRunner that overrides the parent classloader in the meantime.

Thanks for tracking down the problem, these classloader bugs are always super tricky.

from gwtmockito.

tazle avatar tazle commented on May 9, 2024

Yes, what I did for the version I'm now using in IDEA and with plain Maven is exactly as you described.

And yes, the reasoning sounds correct as well. If you are not interested in resources tied to a particular class, the thread context classloader is always the best bet.

I thought creating a custom subclass would not be all that simple in 1.1.5, but looking at it again now, it seems I might be mistaken. I'll probably try that on Monday.

Edit:
Tried to work around this by subclassing in 1.1.5. Overriding getParentClassloader() isn't enough, since the parent class loder isn't explicitly added to the classpath of the ClassPool in 1.1.5. master or 1.1.6 fixes this.

from gwtmockito.

tbroyer avatar tbroyer commented on May 9, 2024

If I understand correctly, IDEA's test runner presumably works by starting a thread, setting that thread's context classloader to something magical, then executing the test on that thread.

Or more likely just setting the current thread's context classloader to some kind of URLClassLoader to simply isolate your project's classpath from IDEA test runner's one.
Maven uses some similar techniques under certain conditions so it can happen there too: https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html

from gwtmockito.

ekuefler avatar ekuefler commented on May 9, 2024

Alright, I've made the change and pushed a new snapshot to Maven. Been a while since the last release, so I'll release 1.1.6 in a week or so if no one reports any problems

from gwtmockito.

tazle avatar tazle commented on May 9, 2024

Still no 1.1.6 release.

from gwtmockito.

ekuefler avatar ekuefler commented on May 9, 2024

Apologies for the long delay. 1.1.6 has been released and should now be available on Maven Central.

from gwtmockito.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.