[go: up one dir, main page]

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

Deprecate usage of TCCL in Loader/LoaderUtil #2850

Open
ppkarwasz opened this issue Aug 16, 2024 · 2 comments
Open

Deprecate usage of TCCL in Loader/LoaderUtil #2850

ppkarwasz opened this issue Aug 16, 2024 · 2 comments
Milestone

Comments

@ppkarwasz
Copy link
Contributor

As a complement to #1977, we should probably remove the usage of the thread context classloader from Loader and LoaderUtil in 2.x

The usage of Loader.loadClass(String) and LoaderUtil.loadClass(String) and similar methods is extremely prone to memory leaks, since the result of such a call is often assigned to a static field.

The thread context classloader is often the classloader of a web application that can be stopped and restarted at will. Any object that we obtain from it must be kept in a weak reference.

IMHO, we should always provide an explicit classloader to load a class by name and we can only choose between:

  • the classloader that loaded log4j-core or log4j-api,
  • the classloader associated with the current LoggerContext.
@vy
Copy link
Member
vy commented Aug 26, 2024

I support this idea; to be more precise: to replace TCCL-as-a-fallback usages with CLs of log4j-core, log4j-api, or LC.

@ppkarwasz
Copy link
Contributor Author

I support this idea; to be more precise: to replace TCCL-as-a-fallback usages with CLs of log4j-core, log4j-api, or LC.

By default TCCL is not a fallback, it is the first one used. That is what makes it so dangerous. The ClassLoader of the LC should be its replacement, which should solve one of the problems we have in a Jakarta environment: if Log4j Core is in the system classloader, you can not use the Web Lookup in a web application classloader.

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

No branches or pull requests

2 participants