Skip to content

VaadinService classloader is incorrectly set in the CTOR #4367

Closed

Description

@denis-anisimov

There is a method setDefaultClassLoader which is called in the VaadinServiceCTOR.

(By the way this is horrible that we have protected method which is intended to be overwritten in subclasses which is called in the CTOR but that's another issue).

This method sets the classloader for the VaadinService to the Thread.currentThread().getContextClassLoader().

Apparently this is intentional code which is done to be able to acquire appropriate class loader to load application's classes (e.g. UI) (from javadocs).

Not sure whether this is done for OSGi case or not but exactly for OSGi it doesn't work.

It might be that it depends on how OSGi declares and uses Vaadin HTTP servlet.

I have an Activator class which register the servlet via HTTP service (see code below).
I have to do it as it's in the code (with one more call for setClassLoader) otherwise it fails with inability to load UI class.

We should take care about this way of activating servlet.

public class Activator implements BundleActivator {

    @Override
    public void start(BundleContext ctx) throws Exception {
        Hashtable<String, String> props = new Hashtable<>();
        props.put("osgi.http.whiteboard.servlet.pattern", "/");
        VaadinServlet servlet = new VaadinServlet() {
            @Override
            public void init(ServletConfig servletConfig)
                    throws ServletException {
                super.init(servletConfig);

                getService().setClassLoader(getClass().getClassLoader());
            }
        };

        ctx.registerService(Servlet.class.getName(), servlet, props);

    }

    @Override
    public void stop(BundleContext context) throws Exception {
    }

}

Activity

  1. added this to the During 2018 candidates milestone on Jul 19, 2018
  2. modified the milestones: Candidates, on Nov 22, 2018
  3. removed this from the milestone on Feb 10, 2020
  4. added a commit that references this issue on Jun 22, 2021
    c95ab77
  5. added a commit that references this issue on Jun 25, 2021
    334d141
  6. added a commit that references this issue on Jun 25, 2021
    17a23ed
  7. added a commit that references this issue on Jun 25, 2021
    1a5a418
  8. added a commit that references this issue on Jun 28, 2021
    6bca15d
  9. vaadin-bot commented on Jun 28, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 21.0.0.alpha8. For prerelease versions, it will be included in its final version.

  10. added a commit that references this issue on Jun 28, 2021
    f913788
  11. vaadin-bot commented on Jul 5, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 20.0.4. For prerelease versions, it will be included in its final version.

  12. vaadin-bot commented on Aug 9, 2021

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with platform 14.7.0.alpha3 and is also targeting the upcoming stable 14.7.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions