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

Continue without setting TCCL #447

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,18 @@ Object setContextFinder() {
ClassLoader previousTCCL = currentThread.getContextClassLoader();
ClassLoader contextFinder = container.getContextFinder();
if (previousTCCL != contextFinder) {
currentThread.setContextClassLoader(container.getContextFinder());
return previousTCCL;
try {
currentThread.setContextClassLoader(container.getContextFinder());
return previousTCCL;
} catch (SecurityException e) {
guw marked this conversation as resolved.
Show resolved Hide resolved
guw marked this conversation as resolved.
Show resolved Hide resolved
// move on without setting TCCL (https://github.com/eclipse-equinox/equinox/issues/303)

if (debug.DEBUG_GENERAL) {
Debug.printStackTrace(e);
}

return Boolean.FALSE;
}
}
return Boolean.FALSE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,22 @@ public Object getService(Bundle bundle, ServiceRegistration<Object> registration
* TCCL loads.
*/
final ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader();
boolean restoreTccl = true;
try {
BundleWiring wiring = bundle.adapt(BundleWiring.class);
ClassLoader cl = wiring == null ? null : wiring.getClassLoader();
if (cl != null)
Thread.currentThread().setContextClassLoader(cl);
if (cl != null) {
try {
Thread.currentThread().setContextClassLoader(cl);
} catch (SecurityException e) {
guw marked this conversation as resolved.
Show resolved Hide resolved
guw marked this conversation as resolved.
Show resolved Hide resolved
// move on without setting TCCL (https://github.com/eclipse-equinox/equinox/issues/303)
restoreTccl = false;
}
}
return createService();
} finally {
Thread.currentThread().setContextClassLoader(savedClassLoader);
if (restoreTccl)
Thread.currentThread().setContextClassLoader(savedClassLoader);
}
}

Expand Down Expand Up @@ -85,4 +93,4 @@ private Object createService() {
public void ungetService(Bundle bundle, ServiceRegistration<Object> registration, Object service) {
// Do nothing.
}
}
}
Loading