Skip to content

Do not expose gocd server class-loader to a plugin #4971

@bdpiprava

Description

@bdpiprava
Issue Type
  • Bug Report
Summary

GoCD server classloader is being exposed to the plugin and it creates an issue in certain scenarios. One such scenario is when plugins dependencies are using current thread classloader to load the class.

public static Class loadClass(String className) throws ClassNotFoundException {
  try {
      ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
      return contextClassLoader.loadClass(className);
  } catch (Exception e) {
      return Class.forName(className);
  }
}

Above code will load the specified class using GoCD server classloader and from GoCD server dependencies which cause plugins to not work.

Basic environment details
  • Go Version: Go Version: 18.7.0 (7118-8494e0df4236380e6b1260f21bea2df13703b64c)
Expected Results

It should load the class from dependencies defined in the plugin, not from the server.

Possible Fix

try {
return plugin.handle(apiRequest);
} catch (UnhandledRequestTypeException e) {
LOGGER.error(e.getMessage());
LOGGER.debug(e.getMessage(), e);
throw new RuntimeException(e);
}

Before submitting a request to plugin set current threads classloader to plugins classloader and revert it back to original classloader at the end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions